Why do we have to provide WSGI_APPLICATION variable in Django settings

北战南征 提交于 2019-12-06 03:25:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/36105946/why-do-we-have-to-provide-wsgi-application-variable-in-django-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!