How can you loop through the HttpRequest post variables in Django?
I have
for k,v in request.POST:
print k,v
which is not working properly.
Thanks!
How can you loop through the HttpRequest post variables in Django?
I have
for k,v in request.POST:
print k,v
which is not working properly.
Thanks!
request.POST
is a dictionary-like object containing all given HTTP POST parameters.When you loop through
request.POST
, you only get the keys.To retrieve the keys and values together, use the
items
method.Note that
request.POST
can contain multiple items for each key. If you are expecting multiple items for each key, you can uselists
, which returns all values as a list.For more information see the Django docs for
QueryDict
.