通过uWSGI运行时Django忽略环境变量 [英] Django ignoring environment variables when run via uWSGI

查看:87
本文介绍了通过uWSGI运行时Django忽略环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django网站,该网站使用环境变量 DJANGO_MODE 来决定要使用的设置-开发还是暂存.环境变量位于 bashrc 中,并且在使用开发服务器运行应用程序时,一切正常.

I have a django website, that uses an environment variable, DJANGO_MODE to decide which settings to use - development or staging. The environment variable is in the bashrc and when running the app using the development server, everything works fine.

但是当我使用 uWSGI 运行应用程序时,似乎没有注意到环境变量,而是使用默认(开发)设置而不是生产版本.

But when I run the app using uWSGI, it doesn't seem to notice the environment variable and uses the default(development) settings instead of production.

我在Emperor模式下运行 uWSGI ,除了忽略环境变量外,其他一切似乎都运行良好.是的,运行 uWSGI 的用户与 bashrc 设置了 DJANGO_MODE 的用户相同.

I run uWSGI in Emperor mode, and other than the environment variable ignoring, everything seems to be running fine. And yes, the user running uWSGI is the same for which the bashrc has DJANGO_MODE set.

用于运行 uWSGI 的命令是-

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

以及 ini的 ini 文件-

[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

推荐答案

由于bash读取bash配置文件,因此无法使用.您必须在皇帝或附庸国中设置var(第二种方法是更好的方法).只需添加

It cannot work as bash config files are read by the bash. You have to set var in the emperor or in the vassal (the second one is a better approach). Just add

env=DJANGO_MODE=foobar

到您的配置(请勿使用空格).

to your config (do not use whitespace).

这篇关于通过uWSGI运行时Django忽略环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆