open a python script on click flask 1

open a python script on click flask

@app.route('/run-script')
def run_script():
   result = subprocess.check_output("python main.py", shell=True)
   return render_template('results.html', **locals())

Here is what the above code is Doing:
1. We import the subprocess module.
2. We create a route called /run-script.
3. We use the subprocess.check_output() function to run the script.
4. We render the results.html template and pass the result variable to it.
5. We create a results.html template that displays the result.

Similar Posts