So I have an html page like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Find the words</title>
<h1>Find the Words</h1>
</head>
<body>
<p>Find the largest and the smallest word</p>
<textarea rows="25" cols="100"></textarea>
<br>
<button type="button">Find now!</button>
<br><br>
<label>Largest Word</label>
<input type='largest word'/>
<label>Smallest Word</label>
<input type='smallest word'/>
</body>
</html>
I want to run a python script which will find the largest and smallest word from a text and post the result back. The script(words.py) is like this:
#!/usr/bin/env python3
def find_small_large_words(given_string):
new_list = given_string.split(" ")
sorted_list = sorted(new_list, key=len)
return 'Smallest: {0} & Largest: {1}'.format(sorted_list[0], sorted_list[-1])
words = "Ten years on from the financial crisis, it’s hard not to have a sense of déjà vu.Financial scandal and wrangles over financial rule-making still dominate " \
"the headlines.The cyberhacking at Equifax compromisedpersonal records for half of the adult population of the United States.At SoFi, a one-time fintech darling"
print(find_small_large_words(words))
Ultimately, I want to run the python script on click of the "Find words" button and post them back in the two boxes. How can I do that here? I have read some suggestions about using django framework. Is there any other simple way? If so, how?
Edit: I am trying this in flask. My code so far:
#!/usr/bin/env python3
from flask import *
from flask import render_template
app = Flask(__name__)
@app.route('/', methods = ['GET', 'POST'])
def homepage():
import words
return render_template("index.html")
if __name__ == "__main__":
app.run()
However, I am unsure how to execute the python script specifically on the textarea input and post the output back.
cgi. Other than that, read the tutorial of your favourite web frame work.