【发布时间】: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