So this is a bit of a newbie question I think, but my issue is basically that I have created a program in python, where it takes an input and gives an output.
I would like to create a localhost site, where you can write your input, then that will be used in the python function, and then the output will be shown on the website.
I've created the 'website' and the python code, but currently, I am stuck in getting the input from html into python and then using that input on the function in python. How does this work? I've used flask so far, but can't make it work. I've created the 'website' and the python code.
What is the easiest way of doing this?
-
You could "store" your input somewhere. (in a sql database, for example.) Then, you can easily access to it.BlackMath– BlackMath2021年08月06日 12:11:03 +00:00Commented Aug 6, 2021 at 12:11
4 Answers 4
If you are using flask, you could create a form in html and write an endpoint in flask to receive form data.
For example:
from flask import Flask, request
app = Flask()
@app.route('/', methods=['GET', 'POST'])
def index():
data = request.form['input_name']
return str(your_func(data))
Also, https://streamlit.io/ might be a more simple solution to your problem.
2 Comments
data=request.form['input_name'] sets the variable 'data' to the form value you are trying to access, and then you can treat the variable however you want.Check out this thread here. I guess using beautifulSoup should do the trick!
Comments
one of the easiest way is to use DJANGO framework. DJANGO is designed to connect between the database (back-end), the front-end & the controller. but in your software you can ignore the database.
Comments
If you are using PHP
you can use PHP's builtin function shell_exec( $cmd ).
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string.
you can use it like that
$cmd = "python YourPythonScript.py $InputFromHTML";
$OutPut = shell_exec( $cmd ) ;
Use $OutPut in your HTML.