0

I have a Pandas/Flask/Jinja2 implementation which processes data taking several minutes. I want to direct processing status to the webpage while the processing occurs. The problem is that nothing appears on the web page until the end of the program. Here is the Python Script:

'''

from flask import Flask, render_template
import time

def print_to_page(output):
    return render_template('list.html', output=output)

app = Flask(__name__)
@app.route("/")
def index():
    return render_template('index.html')

@app.route("/liststuff", methods=('GET', 'POST')) 
def liststuff():
    output = []
    for x in range(5):
        output.append(str(x)+ ' line here')
        time.sleep(5)               # mimics processing occurring
        print_to_page(output)
    return render_template('list.html', output=output)

if __name__ == "__main__":
    print('starting web page.....')
    app.run(debug=True)

'''

Here is the list.html which loops and presents each line of the status:

'''

 <html>
    <head>
        <h3>Printing Stuff</h3>
    </head>
    <body>
        {% for line in output %}
               {{line }} <br>
        {% endfor %}
    </body>

</html>

'''

In Summary, I want the output list to be displayed as the processing occurs (denoted by the sleep timer).....Thanks.

0 Answers0