Reputation: 25
I have a button in html, let's say:
<button type="button">Button</button>
I wish to be able to disable this button through flask (for example after it has been pushed). What I would like to know is how I would add the disabled attribute onto the button. In other words, turning it into:
<button type="button" disabled>Button</button>
Upvotes: 1
Views: 2171
Reputation: 1245
When you call return render_template('template.html', variables=values)
at the end of your route, pass a boolean:
return render_template('template.html', var1=val1, var2=val2,..., button=button)
You can set the value of button
in your route. Then in your jinja2 template, just put in a branch:
{% if button %}
<button type="button">Button</button>
{% else %}
<button type="button" disabled>Button</button>
{% endif %}
If you need the button to be disabled dynamically after the page is rendered, @ltd9938 is correct, you need javascript.
I read now you mean after it has been pushed, in which case, yes, you need javascript.
Upvotes: 1