Django request.request.get()是否同时包含get和POST参数?

2024-09-29 06:35:06 发布

您现在位置:Python中文网/ 问答频道 /正文

request.POST和request.GET中的参数都在request.request中吗?或者我要检查每一个?

我在文档中找不到请求/QueryDict的明确信息。 注:Django 1.4决赛


Tags: django文档信息参数getrequestpostquerydict
3条回答

试试这个:

name=request.GET.GET('name',request.POST.GET('name'))

是的,医生说:

HttpRequest.REQUEST For convenience, a dictionary-like object that searches POST first, then GET. Inspired by PHP’s $_REQUEST.

For example, if GET = {"name": "john"} and POST = {"age": '34'}, REQUEST["name"] would be "john", and REQUEST["age"] would be "34".

It’s strongly suggested that you use GET and POST instead of REQUEST, because the former are more explicit.

不,这在旧版本中是可能的,但在Django 1.7中被贬值了。对于运行古代版本的Django考古学家,继续阅读。

documentation

HttpRequest.REQUEST请求

为了方便起见,一个类似字典的对象先搜索POST,然后再搜索GET。灵感来自PHP的$请求。

例如,如果GET={“name”:“john”}和POST={“age”:“34”},则REQUEST[“name”]将是“john”,REQUEST[“age”]将是“34”。

强烈建议您使用GET和POST而不是REQUEST,因为前者更明确。

相关问题 更多 >