icn*_*icn 29 python django post httprequest
你怎么能在Django中遍历HttpRequest post变量?
我有
for k,v in request.POST:
print k,v
Run Code Online (Sandbox Code Playgroud)
哪个不能正常工作.
谢谢!
Ala*_*air 90
request.POST 是一个类似字典的对象,包含所有给定的HTTP POST参数.
循环时request.POST,只能获得密钥.
for key in request.POST:
print(key)
value = request.POST[key]
print(value)
Run Code Online (Sandbox Code Playgroud)
要一起检索键和值,请使用该items方法.
for key, value in request.POST.items():
print(key, value)
Run Code Online (Sandbox Code Playgroud)
请注意,request.POST每个键可以包含多个项目.如果您希望每个键有多个项目,则可以使用lists,它将所有值作为列表返回.
for key, values in request.POST.lists():
print(key, values)
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅Django文档QueryDict.