I am new to Flask, using which I am creating a webapp.
I have one main function (execute()) that I am running, and it has a number of print statements that get shown in the terminal when the function is run.
However, I would like to display those statements on the webpage as well through HTML. How can I do so?
I have tried searching for the answer, but nothing has worked so far.
app = Flask(__name__)
class MyForm(FlaskForm):
image = MultipleFileField('image')
@app.route('/', methods=['GET', 'POST'])
def index():
form = MyForm()
if form.validate_on_submit():
for file in form.image.data:
image.save(file)
execute()
return redirect(url_for("process"))
return render_template('index.html', user_form=form)
@app.route('/processing')
def process():
return render_template('process.html')
#function that is being executed.
def execute():
print('Execution started')
for i in range(0,10):
print(i)
print('The execution was completed')
The process.html file is as follows: I want to display the terminal output on this page.
{% extends 'base.html' %}
{% block content %}
<p style="text-align:center; font-size:50px; color:#77C66E">File uploaded successfully</p>
{% endblock %}