vendredi 12 août 2016

How to run python script results on Flask

I have created an app.py and index.html file. My problem is that I want to execute a python script with the input I gathered from POST when submit is clicked, and then display the script output on the same or different html page. I used CGI and Flask. I do not fully know how to proceed. I research online, but couldn't find anything very helpful. Any help would be appreciated.

Here is my code.

from flask import Flask, render_template, request, redirect

app = Flask(__name__)

@app.route("/")
def main():
  return render_template('index.html')


@app.route("/src_code/main.py", methods = ['POST'])
def run_emontio():
  id = request.form['id']
  name = request.form['name']
  url = request.form['url']

  if not id or not name or not url:
     return render_template('index.html')
  else:
      #execute the python script.

if __name__ == "__main__":
  app.run()




Aucun commentaire:

Enregistrer un commentaire