Once the button in my flask template is pressed I'd like it to call a python function defined in app.py that I made to be available to be called within the template by typing the following below where I define the function:
Example function in app.py:
@app.route('/foo')
def foo(x,y):
pass
app.jinja_env.globals.update(foo=foo)
Template:
<button type="button" onclick="myFunction(this)" name="enable" id="{{counter}}"> Enable </button>
In my button I have the onclick attribute just to test that the correct button out of many is pressed using javascript like such:
{% block scripts %}
{{ super() }}
<script>
function myFunction(elem){
if(confirm('Are you sure you want to ' + elem.name) == true){
alert("its done.");
}
else {
return false;
}
}
</script>
{% endblock %}
The issue I'm facing is I need the function that I'm making available within the template to correspond to the correct button. For example, if the button says Enable, then I need to call the enable function defined already or otherwise if the button corresponds to false, I'd like the disable function to be used.
I feel like I'm headed in the right direction but can't get past this part. Please be as detailed as you can.