【问题标题】:Gunicorn Django cannot find wsgi moduleGunicorn Django 找不到 wsgi 模块
【发布时间】:2015-06-11 12:55:38
【问题描述】:

我正在尝试使用 Gunicorn 运行 Django/Python3 应用程序。每个人都同意这很容易,但是部署 Web 应用程序对我来说似乎非常复杂,因为我是在 Java/Tomcat 应用程序上提出的。

所以我安装了 Gunicorn:

$ sudo pip3 install gunicorn

我导航到包含./manage.py 文件的目录并执行:

$ gunicorn my_project/wsgi:application

我得到了一个回溯,其要点是:

ImportError: No module named 'my_project/wsgi'

我的wsgi.py 文件与 Django 生成的完全相同,位于my_project/wsgi.py

"""
WSGI config for titlematch_api project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "titlematch_api.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我正在使用 Python 3、Django 1.8 和 gunicorn 19.3.0

我能够让 gunicorn 运行以下测试:

def app(environ, start_response):
    """Simplest possible application object"""
    data = b'Hello, World!\n'
    status = '200 OK'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response(status, response_headers)
    return iter([data])

我做错了什么?我尝试过使用和不使用 virtualenv。

【问题讨论】:

    标签: python django deployment gunicorn


    【解决方案1】:

    试试:

    gunicorn my_project.wsgi:application
    

    这是一个模块路径,而不是文件系统路径。

    【讨论】:

    • +1,谢谢。我尝试了两次接受这个答案,但两次都收到错误,请接受我的感谢。
    猜你喜欢
    • 2021-08-20
    • 1970-01-01
    • 2015-03-23
    • 2012-09-09
    • 2019-11-16
    • 2012-08-17
    • 1970-01-01
    • 2019-12-26
    • 2015-10-01
    相关资源
    最近更新 更多