2015-03-13 92 views
0

我想了解gunicorn是如何與Django一起工作的。瞭解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應用程序的名稱嗎?

回答

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() 
+1

的文件是不是在項目的根目錄,但主要的應用程序(其中有保存名稱作爲項目本身)內。 – 2015-03-13 20:54:36