通过uWSGI运行时Django忽略环境变量

编程入门 行业动态 更新时间:2024-10-25 20:24:39
本文介绍了通过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忽略环境变量

本文发布于:2023-11-24 05:40:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   uWSGI   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!