title: How can you process a file uploaded with Python-Flask?
body: <p>I've created a basic upload function using flask, based on the tutorial in <a href="https://www.youtube.com/watch?v=bxFaa_FNdL4&amp;t=793s" rel="nofollow noreferrer">this</a> video.</p>
  
  <p>The code in the 'main' python file can be found below. Essentially, when run the 'webpage' has an upload function and once you select file(s), these are added to a folder which is either created or exists already alongside the other folders in the flask programme. </p>
  
  <p>My question is this: I want to upload files to be immediately processed by another block of non-flask python code- what principles should be followed to do this? For example- to process a CSV file with a python script? Can the python script theoretically just be residing in a HTML file in the templates folder which gets activated when a suitable file is uploaded?</p>
  
  <pre><code>import os
  from flask import Flask, render_template, request
  
  
  app = Flask(__name__)
  
  APP__ROOT = os.path.dirname(os.path.abspath(__file__))
  
  @app.route("/")
  def index():
      return render_template("upload.html")
  
  @app.route("/upload", methods=['POST'])
  def upload():
      target = os.path.join(APP__ROOT, 'data/')
      print(target)
  
      if not os.path.isdir(target):
          os.mkdir(target)
  
      for file in request.files.getlist("file"):
          print(file)
          filename = file.filename
          destination = "/".join([target, filename])
          print(destination)
          file.save(destination)
  
      return render_template("complete.html")
  
  if __name__ == "__main__":
      app.run(port=4555, debug=True)
  </code></pre>