How to save the selected options from a multi select drop down in a Django variable as a list ? Is there anything to be imported from the .html to .py?
Asked
Active
Viewed 485 times
0
-
maybe you meant how get value from multiple dropdown in Django views ? – Diego Avila Jun 24 '19 at 21:24
-
Basically, I want to make use of that list in a python script(not views). – surresh kummar Jun 27 '19 at 06:57
1 Answers
0
To get the values from multiple dropdown the method is:
Template(myPage.html):
<select multiple="multiple" name="services" id="services" size="5">
{% for service in services %}
<option value="{{ service.pk }}">{{ service.name }}</option>
{% endfor %}
</select>
Views(views.py):
myServices = request.POST.getlist('services')
good luck..!!

Diego Avila
- 700
- 7
- 24
-
Like there are over 600 options. Should I enter service.pk for all 600 options?? – surresh kummar Jun 25 '19 at 05:50
-
-
each of the options must have its id(pk), Django by default define the "ID" in this case is "id-> autoincrement integer" – Diego Avila Jun 25 '19 at 12:35
-
i suggest implement this: https://stackoverflow.com/questions/43917791/how-create-multiple-select-box-in-django – Diego Avila Jun 25 '19 at 12:37