enable a disabled html button based in django template

Issue

I want to enable below button based on the boolean value from context i.e. {{ enable }}.
if enable is True then make it enable otherwise disabled.

<input type="submit" name="upload" class="btn btn-primary" value="Upload" disabled/>

Solution

do this:

{% if enable %}
<input type="submit" name="upload" class="btn btn-primary" value="Upload" />

{% else %}
<input type="submit" name="upload" class="btn btn-primary" value="Upload" disabled/>

{% endif %}

Answered By – Piyush Maurya

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published