Search code examples
djangoformstemplatescheckbox

How to render a checked checkbox in Django template


I need to check that if a checkbox is checked in django template and if False open up some other fields. I already tried something like:

{% if 'closed' in 'is_closed %}

but they are always True and no matter if the checkbox is checked or not so this is my checkbox properties in template

<input type="checkbox" name="is_closed" value="closed">

Solution

  • You need to use checked property by html

    <input type="checkbox" name="is_closed" value="closed" {% if 'closed' in 'is_closed %} checked {% else %} '' {% endif %}>