为什么我们必须在Django设置中提供WSGI_APPLICATION变量 [英] Why do we have to provide WSGI_APPLICATION variable in Django settings
问题描述
我是Django的初学者,所以如果这个问题没有道理,请原谅我.
I'm a beginner Django developer so if this question doesn't make sense please forgive me.
我们在Django设置中提供了一个名为WSGI_APPLICATION
的变量,以及ROOT_URLCONF
和其他一些设置变量.并且我们还在wsgi.py文件中提供了设置文件路径,
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?
我的意思是wsgi文件中的设置文件路径和wsgi文件中的wsgi文件路径.那么为什么我们必须这样做.
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.
根据我对wsgi文件中设置文件的了解的路径应该足够好,而我们在Django设置中不需要那个额外的变量吗?
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?
最后,wsgi文件是django应用程序的起点,对吧?
ultimately the wsgi file is the starting point of django application, right?
请在错误之处纠正我.
PLease correct me wherever I'm wrong.
推荐答案
最终,wsgi文件是django应用程序的起点,对吧?
不一定. WSGI_APPLICATION
的文档说明了此设置的用途:
Not necessarily. The documentation for WSGI_APPLICATION
explains what this setting is for:
Django内置服务器(例如
runserver
)将使用的WSGI应用程序对象的完整Python路径.
The full Python path of the WSGI application object that Django’s built-in servers (e.g.
runserver
) will use.
您设置的任何服务器都必须知道WSGI文件在哪里.如果您使用的是外部服务器,它将查看其自身的设置.如果您使用的是Django的开发服务器,它将检查Django的设置.因此,您注意到的循环性是可以通过多种不同方式启动Django应用程序的结果.
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.
这篇关于为什么我们必须在Django设置中提供WSGI_APPLICATION变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!