title: Python Flask calling functions using buttons
body: <p>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:</p>
  
  <p>Example function in app.py:</p>
  
  <pre><code>@app.route('/foo')
  def foo(x,y):
      pass
  app.jinja_env.globals.update(foo=foo)
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>&lt;button  type="button" onclick="myFunction(this)" name="enable" id="{{counter}}"&gt; Enable &lt;/button&gt;
  </code></pre>
  
  <p>In my button I have the onclick attribute just to test that the correct button out of many is pressed using javascript like such:</p>
  
  <pre><code>{% block scripts %}
      {{ super() }}
      &lt;script&gt;
      function myFunction(elem){
          if(confirm('Are you sure you want to ' + elem.name) == true){
              alert("its done.");            
           }
           else { 
              return false;
           }          
      }
      &lt;/script&gt;
  {% endblock %}
  </code></pre>
  
  <p>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. </p>
  
  <p>I feel like I'm headed in the right direction but can't get past this part. Please be as detailed as you can. </p>