Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting DJANGO_SETTINGS_MODULE under virtualenv?

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?

like image 596
Jim Hefferon Avatar asked Sep 29 '11 14:09

Jim Hefferon


People also ask

Where do I set Django_settings_module?

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.

What is OS environ Setdefault?

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 .


1 Answers

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"
like image 193
Joe J Avatar answered Sep 27 '22 19:09

Joe J