Django ignores environment variables when launched via uWSGI

I have a django site that uses an environment variable, DJANGO_MODE , to decide which settings to use - development or step. The environment variable is in bashrc and when you start the application using the development server everything works fine.

But when I run the application using uWSGI , it does not seem to notice the environment variable and uses the default settings (development) instead of production.

I run uWSGI in Emperor mode, and besides ignoring the environment variable, everything works fine. And yes, the user running uWSGI is the same for which bashrc has DJANGO_MODE .

The command used to start uWSGI is

 exec uwsgi --emperor /etc/uwsgi/vassals --uid web_user --gid --web_user 

And the ini file for the vassal is

 [uwsgi] processes = 2 socket = /tmp/uwsgi.sock wsgi-file = /home/web_user/web/project_dir/project/wsgi.py chdir = /home/web_user/web/project_dir virtualenv = /home/web_user/.virtualenvs/production_env logger = syslog chmod-socket = 777 
+7
django uwsgi
source share
1 answer

It cannot work because bash configuration files are read using bash. You must install var in the emperor or in the vassal (the second is the best approach). Just add

 env=DJANGO_MODE=foobar 

into your configuration (do not use spaces).

+9
source share

All Articles