Django WSGI and Gunicorn

2019-07-16 05:45发布

问题:

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?

回答1:

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.



回答2:

I have Gunicorn to host my django site and this is the config details hope this is helpfull