[Answered ]-Django ChoiceField: Fail to access choices in template

2👍

From the Django documentation (https://docs.djangoproject.com/en/dev/ref/forms/widgets/):

New in Django 1.4 – For more granular control over the generated markup, you can loop over the radio buttons in the template. Assuming a form myform with a field beatles that uses a RadioSelect as its widget:

  {% for radio in myform.beatles %}
  <div class="myradio">
      {{ radio }}
  </div>
  {% endfor %}
👤LukV

0👍

Why are you doing it like this? You should let the field output itself, including the selected field. If you need to set one of the choices to be selected, you should do it in the view or the form, with the initial parameter:

    context.update({
        'searchForm': MultiSearchForm(initial={'mode': your_choice}),
    })

Leave a comment