Django: using <select multiple> and POST

I use something similar in my template

<select multiple="multiple" name="services" id="services" size="5"> {% for service in services %} <option value="{{service.id}}">{{service}}</option> {% endfor %} </select> 

When I view POST data in Firebug or Django debugging, I see that it sends only one value. Am I doing something wrong or misunderstanding the concept?

+42
python django
Mar 06 '09 at 11:39
source share
5 answers
 request.POST.getlist('services') 
+107
Mar 06 '09 at 12:06
source share

Just FYI, I had to use:

  list = request.POST.getlist("items[ ]") 

since removing [] led to returning an empty list instead of the correct values. I use jQuery to retrieve the values ​​of several select elements, and jQuery seems to add []

+7
Jul 05 '11 at 18:31
source share

Beware! The getlist method from QueryDict returns an empty list if the key does not exist. This is no exception. http://bit.ly/MdgrUH

+1
Dec 6
source share

you can get the expected list just using ...

 request.POST.getlist('fiel_name') 
0
Jul 28 '17 at 13:36 on
source share

request.POST.getlist ('services')

Worked for me. or you can define the name of the selection box as a list

0
Aug 24 '17 at 12:13
source share



All Articles