I want the environment variable DJANGO_SETTINGS_MODULE to change depending on what I say for workon. It seemed to me that I want to set it in .virtualenvs/postmkvirtualenv
but my trial had no effect.
ftpmaint@millstone:~$ cat ~/.virtualenvs/postmkvirtualenv
#!/bin/bash
# This hook is run after a new virtualenv is activated.
export DJANGO_SETTINGS_MODULE=newproject.settings
ftpmaint@millstone:~$ echo $DJANGO_SETTINGS_MODULE
az.settings
ftpmaint@millstone:~$ workon newproject
(newproject)ftpmaint@millstone:~$ echo $DJANGO_SETTINGS_MODULE
az.settings
Could someone set me straight; where should I put that export?
In addition, will it restore when I deactivate? And if not, is there some natural way to restore it?
The value of DJANGO_SETTINGS_MODULE should be in Python path syntax, e.g. mysite. settings . Note that the settings module should be on the Python import search path.
setdefault() , environ is an instance of class _Environ , which inherits from IterableUserDict , and IterableUserDict inherits from UserDict , including setdefault() . This method is also a method of UserDict , take a look at the functions implemented by setdefault .
One way I've done that before is by appending an export statement to the end of ./bin/activate
export DJANGO_SETTINGS_MODULE="myproject.settings"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With