title: Flask - Calling python function on button OnClick event
body: <p>I am new to python and Flask.
  I have a Flask Web App with a button. When I click on the button I would like to execute a python method not a Javascript method. How can I do this?</p>
  
  <p>I have seen examples with python where it redirects me to a new page using a form tag like this</p>
  
  <pre><code>&lt;form action="/newPage" method="post"&gt;
  </code></pre>
  
  <p>but I don't want it to redirect me to a new page. I just want it to execute the python method. 
  <strong>I am making this for a Raspberry Pi robot car</strong>. When I press the forward button, I want it to run the method to Turn wheels forward. </p>
  
  <p>Button HTML Code (<strong>index.html</strong>)</p>
  
  <pre><code>&lt;button name="forwardBtn" onclick="move_forward()"&gt;Forward&lt;/button&gt;
  </code></pre>
  
  <p>simple app.py Code - move_forward() method located here</p>
  
  <pre><code>#### App.py code
  
  from flask import Flask, render_template, Response, request, redirect, url_for
  app = Flask(__name__)
  
  @app.route("/")
  def index():
      return render_template('index.html');
  
  def move_forward():
      #Moving forward code
      print("Moving Forward...")
  </code></pre>
  
  <p>I have seen similar questions to mine on Stackoverflow, but they don't seem to answer my question or I am unable to understand the answer. If someone could please provide me a simple way to call a Python method on button click event, it would be greatly appreciated.</p>
  
  <p>Other Questions that I have looked at: </p>
  
  <p>--<a href="https://stackoverflow.com/questions/30899484/python-flask-calling-functions-using-buttons">Python Flask calling functions using buttons</a></p>
  
  <p>--<a href="https://stackoverflow.com/questions/40583347/calling-a-python-function-with-a-button">Calling a python function with a button</a></p>
  
  <p>--<a href="https://stackoverflow.com/questions/21566649/flask-button-run-python-without-refreshing-page">Flask Button run Python without refreshing page?</a></p>