Aug-17-2022, 11:44 AM
I'm trying to get a function to run in the background when accessing my flask application then update the content of the page when the function is completed. Could anyone give me some advice of how i can do this.
Here is an example of what i want to do:
app.py
Here is an example of what i want to do:
app.py
from flask import Flask, render_template from time import sleep from random import random app = Flask(__name__) def dummy_function(): sleep(5) return random() @app.route('/') def index(): x = dummy_function() # run this i background and when it is done update the page return render_template('index.html', x=x) # I want this to render even if the dummy function isn't done if __name__ == '__main__': app.run(debug=True)index.html
<html> <body> <p>x is {{ x }}</p> </body> </html>