[Answer]-Get virtualenv variables in settings file with wsgi

1👍

✅

The postactivate file is a hook called when you use the workon command in bash. In your case, you call the python script activate_this.py.

I manage my settings the same way but I have a postactivate_this.py file in order to set my environment variables as in my postactivate file :

from os import environ

environ["DJANGO_SECRET_KEY"] = "..."
# etc.

Then in your wsgi.py file you can write :

activate_env = os.path.expanduser(envP + '/bin/activate_this.py')
postactivate_env = os.path.expanduser(envP + '/bin/postactivate_this.py')

execfile(activate_env, dict(__file__=activate_env))
execfile(postactivate_env, dict(__file__=postactivate_env))

You don’t need a separate settings file.

Leave a comment