title: Run python script with a button from my website
body: <p>I am currently trying to create a website with Flask that contains just one button (for now). If I press that button I want to run a python script from a specific path or just the project folder. I already saw some posts about the same topic but none of them could really help me.</p>
  
  <p>I already have some code.
  This is my Flask app.py</p>
  
  <pre><code>from flask import Flask, render_template, jsonify
  import test
  
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  
  if __name__ == '__main__':
  app.run(debug=True)
  </code></pre>
  
  <p>And that's my index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
   &lt;/head&gt;
   &lt;body&gt;
     &lt;input type="button" id='script' name="scriptbutton" value=" Run Script " onclick="goPython()"&gt;
  
     &lt;script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"&gt;&lt;/script&gt;
  
     &lt;script&gt;
         function goPython(){
             $.ajax({
               type: 'POST',
               url: "/test.py",
               //or some other path like /scripts/test.py
               dataType: "text",
               success: function (data) {
                 alert(data)
               },
               error: function (data) {
                 alert(data)
               }
             });
         }
     &lt;/script&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If I run my flask website and click the button I want to execute my test.py saved in my project folder or somewhere else. I don't know if it is possible that way or if there is a better solution. Right now I am still trying with flask but I can't get my test.py to run.
  When I press the button it just shows me an alert with [object Object]</p>
  
  <p>Basically what I am trying to build is a website with buttons, like a service that runs my scripts in the background that can sometimes take more time to finish. 
  I am not sure if I am misunderstanding the use of ajax in this case.
  Any help would be nice.</p>