Showing a loading message while python function runs

Hi , does anyone know a clean an easy way of displaying a load message (flash or css loaders) which could be displayed while a python function (which dynamically builds html upon POST request) executes code ? I've tried adding : flash("processing request") but it doesn't seem to do anything , i've looked at javascript solutions but i'm not experienced enough and would like to avoid venturing into this territory. I'm looking a for a simple solution which would just tell the user in a clear way to wait while something is happening. Thanks

You can do the processing outside of the usual request-response cycle by running that code in a separate task: and then use ajax in the browser to query the progress of the task and show that to the user.

Thanks for taking a look Glenn, the solution you proposed might be a bit to tricky for a newbie like me. I've reverted to trying to employ javascript (the idea is to have a hidden 'loading' gif on my start page and show it after a click of an 'execute' button and leave it displayed after the dynamically constructed html/results are ready). I've pasted below a simplified version where i'm just trying to call a javascript function which would hide the 'textarea' before I return the 'done' html (delay represents the long function I will be running to get the real html) . Clearly i'm missing something here because clicking the button does not seem to call my javascript function, all that happens is a15 sec wait followed by display of 'done' html - any idea what am I doing wrong ?

from flask import Flask, request

app = Flask(name) app.config["DEBUG"] = True

if name == "main": = True)

@app.route("/", methods=["GET", "POST"]) def home_page():

if request.method == "POST":

    import time

    return "<html>done</html>"

return """

                <script LANGUAGE="JavaScript" src="">
                function hide_text()
                {var ele = document.getElementById("text1");
       = "none";

                <textarea id="text1" rows="15" cols="100" ></textarea>
                <form method="post">
                <p><button onclick="hide_text();" value="Run" >Run </button></p>

You can use the browser developer tools to see whether the function is actually called (You can add a breakpoint in the function and see whether the breakpoint gets triggered)