How do we execute or run python code after the submit button is pressed the html form that I created in index.html.
The following is the index.php code:
<!DOCTYPE html>
<head>
<title>Hello</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="nopol">
<input id="print_nopol" type="submit">
</form>
<?php
system("python /home/pi/python-epson-printer/epson_printer/testpage.py");
?>
</body>
</html>
and below is a python flask application script with the name app.py :
from flask import Flask, request, render_template, Response, redirect, url_for
from os import listdir
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template('index.html')
@app.route('/', methods=['POST'])
def my_form_post():
input_nopol = request.form['nopol']
if request.method == 'POST':
with open('nopol.txt', 'w') as f:
f.write(str(input_nopol))
return render_template('index.html', nopol=input_nopol)
if __name__ == "__main__":
app.run(host='192.168.1.2', port=8080, debug=True)
This python code has a function to insert data into a .txt file and here is the python script path:
/home/pi/server_print/print.py
Thank you for your help.