Ptmlol
Ptmlol

Reputation: 37

Link client input from web page to python script from server and send results back to web page

I have a python script that gets 5 inputs, does some work, and then prints output for 10 seconds until it finishes. I would like that input to be taken from a web app, sent to the server, executed in python and then the result, sent back to the web app to be shown to the client.

My question is this done? I was thinking in having a HTML+CSS+VUE front end, but I don't know how to link the inputs from the html, to the python script and then back to the html async ( because I want the page to show the real time results ). What backend should I use and how to link those inputs to and results to the web page?

Thank you!

Upvotes: 1

Views: 454

Answers (1)

electromeow
electromeow

Reputation: 251

You can use a basic API. You will create a form like this:

<form method="POST action="/your/path">
<input type="text" name="input1">
<input type="text" name="input2"> 
<input type="text" name="input3"> 
<input type="text" name="input4"> 
<input type="text" name="input5">
<button type="submit" value="Submit">
</form>

I don't know which framework you use but I suppose that you are using Flask:

@app.route("/your/path", methods=["POST"])
def executeTheInfos():
    #Execute your code and render your HTML page to return
    return yourRenderedPage

When you submit the data to HTML form, it will POST the info to /your/path in JSON format like {"input1":"value1", "input2":"value2"...} and at the back-end you will render the response page and return it to user.

Upvotes: 2

Related Questions