Django request.data dictionary returns last item instead of list for post data from a form with checkboxes -


i have form contains checkboxes so:

<form action="#" method="post">     <input type="checkbox" name="languages" value="">all<br>     <input type="checkbox" name="languages" value="en">en<br>     <input type="checkbox" name="languages" value="de">de<br>     <input type="checkbox" name="languages" value="ru">ru<br>     <input type="submit" value="preview"> </form> 

when send it, can check , see data under request.data looks this:

mergedict(<querydict: {u'languages': [u'', u'en', u'de']}>, <multivaluedict: {}>) 

i managed selected language list using:

dict(request.data.dicts[0].iterlists())['u'languages']

but seems ridiculous.

trying different way strange behavior. example when try access request.data['languages'] last item list u'de'.

can explain weird behavior? why strange combination of mergedict, querydict , multivaluedict? , how should best extract list of checked values it?

try to:

request.data.getlist('languages') 

i have same problem,

<querydict:  { 'hobbies': [        'gaming',         'browsing',         'coding'      ],  'name': ['elan'], 'email': ['elanian@gmail.com'], 'gender': ['w'], 'works': ['d'] } > 

i try in view :

print(form.data.getlist('hobbies')) 

and show result

.... ['gaming', 'browsing', 'coding'] [19/oct/2015 19:24:33] "post /lecturer/add/ http/1.1" 200 2158 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -