为什么 gunicorn 看不到当前的环境变量?
Why does gunicorn not see the corrent environment variables?
在我的生产服务器上,我在我的 virtualenv 内部和外部都设置了环境变量(只是因为我不明白这个问题是怎么回事)包括一个变量 HELLO_WORLD_PROD
我已经设置为 '1'
。在 python 解释器中,在我的 venv 内部和外部,os.environ.get('HELLO_WORLD_PROD') == '1'
returns True
。在我的设置文件夹中,我有:
import os
if os.environ.get('HELLO_WORLD_PROD') == '1':
from hello_world.settings.prod import * # noqa
else:
from hello_world.settings.dev import * # noqa
prod.py 和 dev.py 都继承自 base.py,并且在基础 DEBUG = False
中,只有 dev.py 继承了 DEBUG = True
。
但是,当我通过浏览器触发错误时,我看到的是调试页面。
我正在使用 nginx 和 gunicorn。为什么我的应用程序导入了错误的设置文件?
你可以看到我的gunicorn conf here
提前感谢您的耐心等待!
我正在使用 sudo service gunicorn start
到 运行 gunicorn。 The problem is service strips all environment variables but TERM, PATH and LANG. To fix it, in my exec
line in my gunicorn.conf I added the environment variables there using the --env 标志,如 exec env/bin/gunicorn --env HELLO_WORLD_PROD=1 --env DB_PASSWORD=secret
等
在我的生产服务器上,我在我的 virtualenv 内部和外部都设置了环境变量(只是因为我不明白这个问题是怎么回事)包括一个变量 HELLO_WORLD_PROD
我已经设置为 '1'
。在 python 解释器中,在我的 venv 内部和外部,os.environ.get('HELLO_WORLD_PROD') == '1'
returns True
。在我的设置文件夹中,我有:
import os
if os.environ.get('HELLO_WORLD_PROD') == '1':
from hello_world.settings.prod import * # noqa
else:
from hello_world.settings.dev import * # noqa
prod.py 和 dev.py 都继承自 base.py,并且在基础 DEBUG = False
中,只有 dev.py 继承了 DEBUG = True
。
但是,当我通过浏览器触发错误时,我看到的是调试页面。
我正在使用 nginx 和 gunicorn。为什么我的应用程序导入了错误的设置文件?
你可以看到我的gunicorn conf here
提前感谢您的耐心等待!
我正在使用 sudo service gunicorn start
到 运行 gunicorn。 The problem is service strips all environment variables but TERM, PATH and LANG. To fix it, in my exec
line in my gunicorn.conf I added the environment variables there using the --env 标志,如 exec env/bin/gunicorn --env HELLO_WORLD_PROD=1 --env DB_PASSWORD=secret
等