本文介绍了Django WSGI和Gunicorn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是非常愚蠢的问题;我试图使用Gunicorn部署Django应用程序。但是,我刚刚创建了如下所示的wsgi.py(wsgi.py在我的根项目文件夹中):

  import os 

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

#此应用程序对象被配置为使用此
的任何WSGI服务器使用#文件。这包括Django的开发服务器,如果WSGI_APPLICATION
#设置点在这里。
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

#在这里应用WSGI中间件。
#from helloworld.wsgi import HelloWorldApplication
#application = HelloWorldApplication(application)

现在我跑了:

  python manage.py run_gunicorn 

Gunicorn会自动拿起这个wsgi.py吗?这个怎么用? (不知道wsgi在做什么)。或者我需要指定一些东西?

解决方案

如果您在Django设置模块的INSTALLED_APPS中列出了gunicorn,命令是: / p>

  python manage.py run_gunicorn 

不是你给的命令。


This might be really stupid question; I'm trying to deploy Django application using Gunicorn. However, I just created wsgi.py which looks like below (wsgi.py is in my root project folder):

import os

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

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

and now I ran:

python manage.py run_gunicorn

Will Gunicorn automatically picks up this wsgi.py? How does this work? (not sure what wsgi is doing). Or do i need to specify something?

解决方案

If you have gunicorn listed in INSTALLED_APPS of Django settings module, the command is:

python manage.py run_gunicorn

Not the command you give.

这篇关于Django WSGI和Gunicorn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:15