Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/>
like image 862
Ketan Soni Avatar asked Dec 06 '22 14:12

Ketan Soni


2 Answers

The simplest way to do that is:

<input type="submit" name="upload" class="btn btn-primary" 
       value="Upload" {% if not enable %}disabled{%endif%} />
like image 122
Pranay Majmundar Avatar answered Feb 04 '23 14:02

Pranay Majmundar


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 %}
like image 31
Piyush Maurya Avatar answered Feb 04 '23 12:02

Piyush Maurya