我在ModelForm中有多个选择。当页面重新加载并出现错误时,我希望显示当前选定的项目。
error: {{ form.recipients.errors }}<br/>
currently selected: <br/>
{% for recipient in form.recipients %} <!--I want some type of loop through only the selected items in my recipients -->
{{ recipient }}<br/>
{% endfor %}
{{ form.recipients }}
答案 0 :(得分:1)
您希望循环字段的值,而不是字段本身:
{% for recipient in form.recipients.value %}
{{ recipient }}
{% endfor %}