Zebraboard
Zebraboard

Reputation: 210

Easiest way to use a input from html into python code?

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?

Upvotes: 0

Views: 1223

Answers (4)

CoreCoder
CoreCoder

Reputation: 419

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.

Upvotes: 0

Mohamed Salah
Mohamed Salah

Reputation: 21

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.

Upvotes: 0

Jett Chen
Jett Chen

Reputation: 382

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.

Upvotes: 1

alighaddar
alighaddar

Reputation: 53

Check out this thread here. I guess using beautifulSoup should do the trick!

Upvotes: 0

Related Questions