2013-02-27 54 views
0

我在ModelForm中有多個選擇。當頁面重新加載錯誤時,我想要顯示選擇的項目。Django顯示多個模板中的選定項目

view.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 }} 
+0

你是什麼意思 「不工作」? – 2013-02-27 22:39:13

+0

對不起,我試圖表達我想要什麼樣的機制。它不起作用,因爲它不是有效的代碼。我會編輯它以更清楚地表達我的觀點。 – 2013-02-27 22:40:40

回答

1

要循環的字段的值,而不是字段本身:

{% for recipient in form.recipients.value %} 
    {{ recipient }} 
{% endfor %}