django 获取环境变量_django – 如何设置nginx读取的环境变量?

我试图在环境变量中设置我的django“SECRET_KEY”.

我使用virtualenv virtualenvwrapper环境.

我输入后

workon mydomain.com

我输了

export SECRET_KEY=xxxxxx

当我尝试做的时候

echo $SECRET_KEY

我得到了我的价值(xxxxxx)

到现在为止还挺好.但是当我尝试在浏览器中访问我的网站时(使用ngnix和gunicorn)我收到了一个错误.

这是我的gunicorn的supervisord脚本

[program:gunicorn]

directory = /home//.virtualenvs///

command=/home//.virtualenvs//bin/gunicorn .wsgi:application -c /home//.virtualenvsgunicorn_conf.py

user =

这是我的gunicorn_conf.py:

bind = "127.0.0.1:8000"

logfile = "/home//logs/gunicorn.log"

这是我的settings.py:

def get_env_variable(var_name):

try:

return os.environ[var_name]

except KeyError:

error_msg = "Set the %s environment variable" % var_name

raise ImproperlyConfigured(error_msg)

SECRET_KEY = get_env_variable("SECRET_KEY")

如何正确设置我的环境变量,以便ngnix可以读取它?

编辑:回溯:

Traceback (most recent call last):

File "/home//.virtualenvs//local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 125, in handle_request

respiter = self.wsgi(environ, resp.start_response)

File "/home//.virtualenvs//downloads/django-trunk/django/core/handlers/wsgi.py", line 236, in __call__

self.load_middleware()

File "/home//.virtualenvs//downloads/django-trunk/django/core/handlers/base.py", line 46, in load_middleware

for middleware_path in settings.MIDDLEWARE_CLASSES:

File "/home//.virtualenvs//downloads/django-trunk/django/conf/__init__.py", line 53, in __getattr__

self._setup(name)

File "/home//.virtualenvs//downloads/django-trunk/django/conf/__init__.py", line 48, in _setup

self._wrapped = Settings(settings_module)

File "/home//.virtualenvs//downloads/django-trunk/django/conf/__init__.py", line 126, in __init__

mod = importlib.import_module(self.SETTINGS_MODULE)

File "/home//.virtualenvs//downloads/django-trunk/django/utils/importlib.py", line 35, in import_module

__import__(name)

File "/home//.virtualenvssettings/staging.py", line 2, in

from .base import *

File "/home//.virtualenvssettings/base.py", line 40, in

SECRET_KEY = get_env_variable("SECRET_KEY")

File "/home//.virtualenvssettings/base.py", line 31, in get_env_variable

raise ImproperlyConfigured(error_msg)

ImproperlyConfigured: Set the SECRET_KEY environment variable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值