I am creating a function that will display the values and the key of querydict. for example if I got a QueryDict on a GET Request.
<QueryDict: {u'val1':[u'aa'],u'val2':[u'ab'],u'val3':[u'ac'],u'val4':[u'ad'], ... u'valn':[u'an'] ...}>
my function is now just like this:
def displayQueryDicts(self, request):
for x in request:
print x # this will return the val1, val2, val3, val4, ..., valn
print x .value() # I don't know how to print all the values
My question now is, how can I print the values just like this..
val1 aa
val2 ab
val3 ac
val4 ad
... ...
valn an
According to the documentation:
HttpRequest.GET
A dictionary-like object containing all given HTTP GET parameters.
You can iterate over it like over a normal python dict
:
for key, value in request.GET.items():
print "%s %s" % (key, value)
Hope that helps.
In python3 you would do
for key, value in request.GET.items():
print ("%s %s" % (key, value))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With