I was looking to convert a dict to a QueryDict in my django project. Couple of links exists to explain this (Django: Can I create a QueryDict from a dictionary? and How to change a django QueryDict to Python Dict?). This is my simple dictionary which I want to convert abc = {'a': 1, 'b':[1,2,3]}
. I have tried this approach:
from django.http import QueryDict
from django.utils.datastructures import MultiValueDict
abc = { 'a': 1, 'b':[1,2,3]}
mdict = MultiValueDict(abc)
qdict = QueryDict(mdict)
This is the error trace I am getting
/usr/lib/python2.7/urlparse.pyc in parse_qsl(qs, keep_blank_values, strict_parsing)
407 Returns a list, as G-d intended.
408 """
409 pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
410 r = []
411 for name_value in pairs:
AttributeError: 'MultiValueDict' object has no attribute 'split'
Why this has failed and how can I get this done? Also what are the differences between MultiValueDict and QueryDict?