enable a disabled html button based in django template

Viewed 7595

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/>
3 Answers

The simplest way to do that is:

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

Try something like this to disable the button based on the condition in Django.

     <input type="button" {% if a==b %} disabled="true" {% endif %}/>

Here 'a' and 'b' refers to the variables coming from the Django view.

Related