python - Gunicorn Django 找不到 wsgi 模块

标签 python django deployment gunicorn

我正在尝试使用 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。

最佳答案

尝试:

gunicorn my_project.wsgi:application

它应该是模块路径,而不是文件系统路径。

关于python - Gunicorn Django 找不到 wsgi 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30781426/

相关文章:

python - pandas to sql 将 datetime64 索引转换为时区感知

python - 在 Python BaseHTTPServer 中获取 GET 和 POST 请求数据

ajax - Django API 请求

ruby-on-rails - 部署到 heroku 时出错:rake Assets :预编译 PG::ConnectionBad:无法连接到服务器:连接被拒绝

java - 如何部署应用程序[寻求建议]

java - Wildfly 部署进入临时文件夹

python - 如何按照我的查询(一个句子分解成一个词元组)的相同顺序对我的 SQL 结果进行排序?

python - Django 刷新 token 轮换和用户页面刷新

django - @shared_task 装饰器不起作用

python - 安装 python 包时弹出消息