使用Gunicorn设置Django应用程序

时间:2015-04-30 09:05:04

标签: python django nginx gunicorn

所以我正在关注数字海洋的这个教程:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

我唯一没做的就是使用数据库引擎而我只是坚持使用SQLite3引擎,因为应用程序很小。我正在尝试运行服务器wgsi文件,它显示导入文件名不支持错误。我不确定如何解决这个问题。

我试过跑:

python manage.py run_gunicorn 127.0.0.0:8001

但它说的是未知命令:'run_gunicorn'并显示帮助它没有显示run_gunicorn

这是我的wgsi文件(取出项目名称):

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xxxx.settings")

from django.core.wgsi import get_wgsi_application
application = get_wgsi_application()

继承人追溯:

Traceback (most recent call last):
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
Traceback (most recent call last):
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/opt/sanderson-holdings/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: Import by filename is not supported.

1 个答案:

答案 0 :(得分:0)

从manage.py run_gunicorn迁移到实际使用gunicorn命令时,我遇到了类似的问题。我发现除了实际的wsgi文件之外,我还必须设置DJANGO_SETTINGS_MODULE以及设置。

我的项目结构:

  • eestecnet /
    • manage.py
    • eestecnet /
      • eestecnet.wsgi
      • 设置/
        • deployment.py

我从root eestecnet文件夹运行以下命令:

gunicorn --env DJANGO_SETTINGS_MODULE=eestecnet.settings.deployment --settings eestecnet.settings.deployment eestecnet.wsgi

在我的设置中我还指定:

WSGI_APPLICATION = 'eestecnet.wsgi.application'

我希望这会对你有所帮助。