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