This is the one used in request.POST
. Note that it was necessary to confirm the difference in behavior with dict
.
The feature is
--Pass the query string to create an instance --Immutable (but you can pass mutable = True) --Holding values in a list (inheriting MultiValueDict)
>>> from django.http import QueryDict
>>> qd = QueryDict('spam=1&egg=2')
#When you get it with get, a string is returned
>>> qd.get('spam')
u'1'
#Get list with getlist returns list
>>> qd.getlist('spam')
[u'1']
#Return to query string
>>> qd.urlencode()
u'egg=2&spam=1'
#Try to set the value
>>> qd['spam'] = 100
AttributeError: This QueryDict instance is immutable
# mutable=Make QueryDict with True
>>> qd2 = QueryDict('spam=1&egg=2', mutable=True)
>>> qd2.get('spam')
u'1'
>>> qd2['spam'] = 100
>>> qd2.get('spam')
100
#Try converting to dict
>>> d = dict(qd)
>>> d.get('spam')
[u'1']
Recommended Posts