[英]Print HTTP request in Python Django
I want to print the entire request object that comes to the server.我想打印到达服务器的整个请求对象。 I need to see all of the parameters that the request carries from the client since I don't have the clients's code (it's an Android client).
我需要查看请求从客户端携带的所有参数,因为我没有客户端的代码(它是一个 Android 客户端)。 I'm in the view.py file, and I'm using the function
我在 view.py 文件中,我正在使用该函数
def index(request):
return HttpResponse("test params")
to print the request object打印请求对象
Please suggest code.请建议代码。 It would be even better if I can print the request in the browser and not in the console.
如果我可以在浏览器中而不是在控制台中打印请求,那就更好了。
You can use Django Debug Toolbar which allows you to view a lot of debugging information including request and session.您可以使用Django 调试工具栏,它允许您查看大量调试信息,包括请求和会话。
From its documentation:从它的文档:
Currently, the following panels have been written and are working:
目前,以下面板已经编写并正在运行:
- Django version
Django 版本
- Request timer
请求计时器
- A list of settings in settings.py
settings.py 中的设置列表
- Common HTTP headers
常见的 HTTP 标头
- GET/POST/cookie/session variable display
GET/POST/cookie/session 变量显示
- Templates and context used, and their template paths
使用的模板和上下文,以及它们的模板路径
- SQL queries including time to execute and links to EXPLAIN each query
SQL 查询包括执行时间和 EXPLAIN 每个查询的链接
- List of signals, their args and receivers
信号列表,它们的参数和接收器
- Logging output via Python's built-in logging, or via the logbook module
通过 Python 的内置日志记录或通过 logbook 模块记录输出
from django.utils.html import escape
def index(request):
return HttpResponse(escape(repr(request)))
import sys
def req(request)
print(request.__dict__, file=sys.stderr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.