title: How to run a python script in the background on click of html button using flask framework
body: <p>''' upload.html'''</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;UTF-8&quot;&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2 style=&quot;color:DodgerBlue;&quot;&gt;File Uploader&lt;/h2&gt;
  
  &lt;form id = &quot;upload-form&quot; action = &quot;{{ url_for('upload') }}&quot; method=&quot;POST&quot; 
   enctype=&quot;multipart/form-data&quot;&gt;
  &lt;input type = &quot;file&quot; name = &quot;file&quot; accept = &quot;files/*&quot; multiple&gt;
  &lt;input type = &quot;submit&quot; value = &quot;submit&quot;&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>''' app.py'''</p>
  <pre><code>import os
  from flask import Flask, request, render_template, send_from_directory
  app = Flask(__name__)
  
  APP_ROOT = os.path.dirname(os.path.abspath(__file__))
  
  @app.route(&quot;/&quot;)
  def index():
      return render_template(&quot;upload.html&quot;)
  
  @app.route(&quot;/upload&quot;, methods=[&quot;POST&quot;])
  def upload():
  
      target = os.path.join(APP_ROOT, 'Athena_XML_files/')
      print(target)
      if not os.path.isdir(target):
          os.mkdir(target)
  
      for file in request.files.getlist(&quot;file&quot;):
          print(file)
          filename = file.filename
          destination = &quot;/&quot;.join([target, filename])
          print(destination)
          file.save(destination)
  
      return render_template(&quot;complete.html&quot;)
  
  @app.route('/run_script')
  def run_script():
      app.config.from_pyfile(&quot;main.py&quot;)
      return render_template('result.html')
  
  if __name__ == &quot;__main__&quot;:
      app.run(port=4555, debug=True)
  </code></pre>
  <p>'''complete.html'''</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;UTF-8&quot;&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;XML files Uploaded&lt;/h1&gt;
  &lt;ul&gt;&lt;br&gt;&lt;br&gt;
  &lt;h2&gt;&lt;strong&gt;Please click to obtain the result&lt;/strong&gt;&lt;/h2&gt;&lt;br&gt;&lt;br&gt;
  &lt;ul class=&quot;nav nav-stacked&quot;&gt;
      &lt;li role=&quot;presentation&quot;&gt;&lt;a href=&quot;{{ url_for('run_script') }}&quot;&gt;CLICK  
  HERE&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>As the XML files are uploaded and the CLICK HERE button is clicked, main.py file should run in the background for which i have made a function in app.py file to run the main.py file.</p>
  <p>Uploading works well, but on click of button the main.py file is not running in the background.</p>