Ketan Soni
Ketan Soni

Reputation: 97

enable a disabled html button based in django template

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

Upvotes: 5

Views: 9782

Answers (3)

Zeeshan Liaqat
Zeeshan Liaqat

Reputation: 106

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.

Upvotes: 0

Pranay Majmundar
Pranay Majmundar

Reputation: 867

The simplest way to do that is:

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

Upvotes: 14

Piyush Maurya
Piyush Maurya

Reputation: 2015

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 %}

Upvotes: 3

Related Questions