after trying for hours I m frustrated with this. I just can't loop over my ChoiceField's choices in the template. It will not even enter the loop. But if I access the form field with pdb it looks fine.
my form:
MODE_CHOICES = (('blue', 'blue'), ('red', 'red'))
class MultiSearchForm(forms.Form):
mode = forms.ChoiceField(required = True, widget = RadioSelect, choices = MODE_CHOICES)
my view:
class LandingPage(TemplateView):
template_name = "landingPage.html"
def get_context_data(self, **kwargs):
context = super(LandingPage, self).get_context_data(**kwargs)
context.update({
'searchForm': MultiSearchForm(),
})
return context
my template:
<ul>
{% for choice in searchForm.mode.choices %} // for loop is not entered
<li>
<input type="radio" name="mode" value="{{choice.0}}"
{% ifequal searchForm.mode.data choice.0 %}
checked="checked"
{% endifequal %}/>
</li>
{% endfor %}
</ul
{{searchForm.mode.choices.0}} //no output
{{searchForm.mode}} // gives me 2 radio buttons