django form: how to check out checkbox state in template

前端 未结 4 1700
情话喂你
情话喂你 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:10

    While, first you should use BooleanField in your model, not the CharField. Then, there are two accesses:

    • just put {{form.yourField}} in your template (preferred)

    • or, use {% if form.yourFiled.value %} checked {%endif%}

提交回复
热议问题