了解 gunicorn 和 Django

Understanding gunicorn and 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 应用程序上下文中的 "application" 是什么?我应该将它指定为我的 Django 应用程序的名称吗?

你的 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()