[英]Get checkbox value in django
我已经在我的html模板中传递了一个python列表(list_exp),现在我想用字典来获取view.py中多个复选框的结果。 {list_exp [0]:对/错,list_exp [1]:对/错.....}
<form action="" method="post">
{% for name in list_exp%}
<input type="checkbox" name="{{name}}"><label> Experiment : {{name}}</label>
<br>
{% endfor %}
<input type="submit" value="Submit">
</div>
</form>
据我所知,如果为每个输入复选框指定相同的名称,则可以在views.py中将它们作为列表引用。
因此在模板中:
{% for name in list_exp %}
<input type="checkbox" name="list_exp"><label> Experiment : {{name}}</label>
<br>
{% endfor %}
然后在views.py中:
request.POST.getlist('list_exp')
将按预期返回列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.