Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we have to provide WSGI_APPLICATION variable in Django settings

I'm a beginner Django developer so if this question doesn't make sense please forgive me.

We provide a variable called WSGI_APPLICATION in django settings along with ROOT_URLCONF and some other settings variables. and we provide settings file path in wsgi.py file as well,

import os
import django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGSS_MODULE", "<settings_file_path>")
application = get_wsgi_application()

So you see, its a two way connection.right?

I mean path of settings file in wsgi file and path of wsgi file in settings file. so why do we have to do this.

as per my understanding path of settings file in wsgi file should be good enough and we dont need that extra variable in django settings?

ultimately the wsgi file is the starting point of django application, right?

PLease correct me wherever I'm wrong.

like image 279
Wendy Avatar asked Mar 19 '16 19:03

Wendy


1 Answers

Ultimately the wsgi file is the starting point of django application, right?

Not necessarily. The documentation for WSGI_APPLICATION explains what this setting is for:

The full Python path of the WSGI application object that Django’s built-in servers (e.g. runserver) will use.

Any server you set up has to know where the WSGI file is. If you're using an external server it will look in its own settings. If you're using Django's development server, it will check Django's settings. So the circularity you noticed is a consequence of the fact that the Django application can be started in a number of different ways.

like image 55
Kevin Christopher Henry Avatar answered Sep 22 '22 12:09

Kevin Christopher Henry