0

我在 ModelForm 中有多项选择。当页面重新加载出现错误时,我希望显示当前选定的项目。

视图.html

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 }}
4

1 回答 1

1

您想循环字段的值,而不是字段本身:

{% for recipient in form.recipients.value %}
    {{ recipient }}
{% endfor %}
于 2013-02-28T03:55:43.243 回答