my problem is that I want to execute a Python programm by pressing a button on a website. I have build a webserver with Flask and on this webserver I run my website with a button. In the directory of my server I have another python script which I want to execute by clicking the button on the website, but so far i didn't manage to do it. I'd be very pleased if someone could help me.
This is how my webserver looks like:
from flask import Flask, render_template
import subprocess
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def programm_ausführen():
cmd1 = 'python3 test_1.py'
p = subprocess.Popen(cmd1, shell=True)
out, err = p.communicate()
print(err)
print(out)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
and this is my html code:
<html>
<head>
<title>Ansteuerung Niryo NED</title>
<link rel="stylesheet" href='C:\Users\Elias\Desktop\webapp\static\style.css' type="text/css" />
</head>
<body>
<h1>Programmauswahl für NED und Datenverarbeitung</h1>
<button name="Programm 1" onclick"programm_ausführen()">Programm 1</button>
</body>
</html>
I want to execute the test_1.py programm via the button mentioned on the website...
best regards
elias
Aucun commentaire:
Enregistrer un commentaire