django form: how to check out checkbox state in template

前端 未结 4 1814
情话喂你
情话喂你 2021-02-06 14:46

I have a form with checkboxes that works fine, but when the user submits the form with errors and my checkbox is checked I need to change div class which holds the checkbox. So

4条回答
  •  广开言路
    2021-02-06 15:15

    Work for me:

    {% for foo in form.tags %}
      

    That:

    {% if foo.choice_value in foo.value %}checked="checked"{% endif %}
    

提交回复
热议问题