Py using html or php input value and output returned result value to html(php)

Asked 2 years ago, Updated 2 years ago, 50 views

I want to do the same thing, but I don't know how to start Help me

python php html

2022-09-20 22:14

1 Answers

How about using Flask? Below is an example of using Flask.

#app.py
from flask import Flask, request
import machine #machinelearningpy

app = Flask(__name__)

@app.route("/")
def main():
    html = '<form action="http://127.0.0.1:8000/submit" name="machine" method="post">\
    <input type="text" name="input">\
    <input type="submit" value="submit"> </form>'
    return html

@app.route("/submit" , methods=['POST'])
def answer():
    if request.method == 'POST':
        data = request.form['input']
        result = machine.input(data)
        return result

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000, debug=True)
#machine.py
def input(x):
    result = 'hi '+ x
    return result


2022-09-20 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.