Wendy
Wendy

Reputation: 1603

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.

Upvotes: 10

Views: 13952

Answers (2)

Kevin Christopher Henry
Kevin Christopher Henry

Reputation: 48902

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.

Upvotes: 7

Leonard2
Leonard2

Reputation: 890

IMHO, wsgi.py plays a role of pointing to where your django project is, for WAS like Apache or something else.

Therefore wsgi.py starts outside of django, it needs django settings.

Upvotes: 0

Related Questions