了解gunicorn和Django

时间:2015-03-13 13:57:12

标签: django gunicorn

我试图了解gunicorn如何与Django一起工作。

Running Django in Gunicorn as a generic WSGI application上的文档说:

At its simplest, gunicorn just needs to be called with the location
of a module containing a WSGI application object named application. 

所以你可以这样做:

$ gunicorn myproject.wsgi

它会运行。但到底是做什么的呢?我正在查看我的Django项目的根目录,但那里没有名为myproject.wsgi的文件。那么神奇的背后是什么?

docs also say

Gunicorn will look for a WSGI callable named application if not specified. 

这是什么意思?什么是"应用"在我的Django应用程序的上下文中?我应该将其指定为我的Django应用程序的名称吗?

1 个答案:

答案 0 :(得分:3)

你的django项目的根目录下应该有一个wsgi.py文件(用django-admin startproject myproject创建)。

此wsgi.py具有application可调用:

"""
WSGI config for myproject 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

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()