如何知道哪些django中间件启用了异步,哪些没有?
要查看 Django 必须适应哪些中间件,您可以打开 Django 的调试日志记录。请求记录器并查找有关“同步中间件……已调整”的日志消息。
我一直在尝试做同样的事情,但没有运气。
这是我的 settings.py 文件:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'DEBUG',
},
'loggers': {
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
},
}
尽管我已经设置了 LOGGING 变量,但我没有得到文档中提到的输出。
Starting server at tcp:port=8000:interface=127.0.0.1
HTTP/2 support not enabled (install the http2 and tls Twisted extras)
Configuring endpoint tcp:port=8000:interface=127.0.0.1
Listening on TCP address 127.0.0.1:8000
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:47] "GET /admin/" 200 3550
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:48] "GET /admin/core/user/" 200 9028
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:48] "GET /admin/jsi18n/" 200 3343
当我运行 daphne 服务器时,
达芙妮项目名称.asgi:应用程序
命令。 任何人都可以帮助我获得有关所有中间件哪些是异步的、哪些不是异步的输出。
我尝试创建一个视图并通过浏览器向它发出请求,但它似乎没有打印任何中间件。尽管已经存在可能使用中间件的管理模型,但没有诸如“同步中间件...适应”之类的输出。
To see what middleware Django has to adapt, you can turn on debug logging for the django. request logger and look for log messages about “Synchronous middleware … adapted” .
I have been trying to do just the same but without any luck.
This is my settings.py file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'DEBUG',
},
'loggers': {
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
},
}
Even though I have set up the LOGGING variable, I am not getting the output like mentioned in the documentation.
Starting server at tcp:port=8000:interface=127.0.0.1
HTTP/2 support not enabled (install the http2 and tls Twisted extras)
Configuring endpoint tcp:port=8000:interface=127.0.0.1
Listening on TCP address 127.0.0.1:8000
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:47] "GET /admin/" 200 3550
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:48] "GET /admin/core/user/" 200 9028
HTTP b'GET' request for ['127.0.0.1', 42684]
HTTP 200 response started for ['127.0.0.1', 42684]
HTTP close for ['127.0.0.1', 42684]
HTTP response complete for ['127.0.0.1', 42684]
127.0.0.1:42684 - - [22/Mar/2022:12:11:48] "GET /admin/jsi18n/" 200 3343
when I run the daphne server using,
daphne project_name.asgi:application
command.
Can anyone help me to get the output about what all middlewares are asynchronous and which are not.
I tried making a view and making a request to it through browser, but it didn't seem to print about any middlewares. Although, there is already the admin model which might be using the middlewares, there is no output of such kind like "synchronous middleware ...adapted".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在问题中使用的记录器非常正确地查看哪些中间件是否启用了异步。但问题是我想知道为什么 Django 提供的中间件没有在这里显示哪些启用了异步,哪些没有。
于是,我尝试自己做一个中间件来检验这个功能。
middleware.py
现在,如果您在 settings.py 文件中添加此中间件,并运行服务器,那么您将看到日志将按预期说明此中间件。
The logger that I have used in the question is quite correct to view which middlewares are asynchronous enabled or not. But the problem was that I was wondering why Django provided middlewares are not showing here which are asynchronous enabled and which are not.
So, I tried to make a middleware on my own to check this feature.
middleware.py
Now, if you add this middleware in the settings.py file, and run the server, then you will see that the log will say about this middleware as intended.