简体   繁体   English

如何在激活虚拟环境之前或之后以及在Windows中停用虚拟环境之前或之后配置虚拟环境挂钩

[英]How to configure virtual environment hooks before or after activating the virtual environment, and before or after deactivating it in Windows

I am new to Django. 我是Django的新手。 I have created the virtual environment. 我已经创建了虚拟环境。 With virtualenvwrapper, there is a way to configure different hooks that are sourced before or after activating the virtual environment, and before or after deactivating it, but I am not sure how to do this. 使用virtualenvwrapper,有一种方法可以配置在激活虚拟环境之前或之后以及在取消激活虚拟环境之前或之后获取的不同挂钩,但是我不确定如何执行此操作。 I am using Windows for this. 我为此使用Windows。 There is a lot of help for this in Linux but I can't find anything for Windows. 在Linux中对此有很多帮助,但是对于Windows我找不到任何东西。

Since you are using windows you should read this thread before. 由于您使用的是Windows,因此您应该先阅读此线程 Once finished and decided to use tools such as powershell , you can do as follow: 完成并决定使用powershell之类的工具后,您可以执行以下操作:

in your virtualenv directory you will find your app folders, under virtualenv_path/app/bin you find all the hooks: 在您的virtualenv目录中,您将找到您的应用程序文件夹,在virtualenv_path/app/bin您将找到所有挂钩:

Example : You need to set DJANGO_SETTINGS_MODULE to tell django use my local setting, you need to set it in each activation of the env and unset it when you deactive the env: 示例 :您需要设置DJANGO_SETTINGS_MODULE来告诉django使用我的本地设置,您需要在每次激活env时进行设置,而在停用env时取消设置:

in postactive file add : export DJANGO_SETTINGS_MODULE="myproject.settings_local" 在后postactive文件中添加: export DJANGO_SETTINGS_MODULE="myproject.settings_local"

and in predeactivate you add: unset DJANGO_SETTINGS_MODULE 并在predeactivate添加:未unset DJANGO_SETTINGS_MODULE

So the variable will be set every time you activate your env and unset every tine you deactivate. 因此,变量将在您每次激活环境时设置,并取消设置每个您停用的例程。 To check if every thing is working correct when you activate your env try in shell: 要在激活环境时检查一切是否正常,请在shell中尝试:

echo $DJANGO_SETTINGS_MODULE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM