django Method for Obtaining value and id of from Form multiple select
- 2021-07-24 11:09:51
- OfStack
As shown below:
<select id="host_list" name="host_list" multiple>
{% for op in host_list %}
<option id="{{ op.nid }}">{{ op.hostname }}</option>
{% endfor %}
</select>
1. When the value of the selected option needs to be obtained,
Need to be set to id= "{{op. nid}}",
django Views Get the selected value is host_value=request. POST. getlist ("host_list")
The obtained value of the selected option;
2. When the id of the selected option needs to be obtained,
It needs to be set to value= "{{op. nid}}",
django Views Get the selected value is host_id=request. POST. getlist ("host_list")
The obtained id is the selected option;