我正在将一个已经在Heroku上的项目迁移到DO droplet。安装顺利进行,当python manage.py runserver 0.0.0.0:8000
时,一切正常。
我现在正在使用这些说明设置gunicorn: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04
我激活虚拟环境,然后尝试--bind 0.0.0.0:3666 myproject.wsgi:application
。我收到以下错误:
Traceback (most recent call last):
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
worker.init_process()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
self.load_wsgi()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
self.wsgi = self.app.wsgi()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/var/www/myproject/myproject/wsgi.py", line 6, in <module>
from configurations.wsgi import get_wsgi_application
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/wsgi.py", line 3, in <module>
importer.install()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 54, in install
importer = ConfigurationImporter(check_options=check_options)
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 73, in __init__
self.validate()
File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 122, in validate
raise ImproperlyConfigured(self.error_msg.format(self.namevar))
ImproperlyConfigured: Configuration cannot be imported, environment variable DJANGO_CONFIGURATION is undefined.
我的wsgi.py
看起来像这样:
# -*- coding: utf-8 -*-
import os
from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()
我最初没有设置项目,所以我不确定有什么不同,或者在哪里看。
答案 0 :(得分:1)
使用此链接并将DJANGO_CONFIGURATION环境变量设置为您刚刚创建的类的名称,例如在bash:
export DJANGO_CONFIGURATION = Dev