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 iteritems method.
def my_view(request):
# loop through keys
for key in request.POST:
value = request.POST['key']
# loop through keys and values
for key, value in request.POST.iteritems():
# do something
For more information see the Django docs.