4

Can anyone help me in understanding what is the use of wsgi.py file?

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
troy
  • 75
  • 1
  • 1
  • 5

2 Answers2

7

This file is basically used for deployment only as is not used in development, except when you are using docker.

It is used as an interface between application server to connect with django or any python framework which implements wsgi specified by python community, taking about usage mostly you will see it is used with gunicorn

  • Sorry, but wsgi file is actually used in default development environment of Django. Source->https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-runserver – Vishwas Patel Dec 05 '21 at 11:29
  • Vishwas - the docs say the WSGI object specified by `settings.WSGI_APPLICATION` is used - it doesn't say the wsgi.py file specifically is used. Couldn't you ditch the file and move the construction of the WSGI app object somewhere else, then update the setting to point to that new location? – odigity Sep 25 '22 at 14:35
2

The main use of deploying with WSGI is the application callable which the application server uses to communicate with your code. It’s commonly provided as an object named application in a Python module accessible to the server.

officialrahulmandal
  • 2,473
  • 1
  • 23
  • 31