Setting ID for Radio buttons in Django

后端 未结 2 1084
天涯浪人
天涯浪人 2021-01-21 03:06

It is great that Django 1.4 allows fine graining of radio select

{% for radio in form.important_client reversed%}
      {{radio.tag}}
2条回答
  •  旧时难觅i
    2021-01-21 03:50

    While debuging a RadioSelect rendering, I got no idea of using radio tag and label elegantly. So here is my attempt to solve your problem:

    {% for radio in form.important_client reversed %}
        
        
    {% endfor %}
    

    Instead of radio.index property, which is not documented, you can use forloop.counter.

    Just in case I attach a screenshot of debug window, where example of radio context is shown (form_of_field variable on a figure): radio select debug

提交回复
热议问题