I want to constantly update my list stuff
by appending more "stuff" in it. However, my list is not updating (preferably every second, but I don't know how to do a while loop inside flask).
Here is my routes.py :
from flask import render_template
from app import app
from win32gui import GetWindowText, GetForegroundWindow
@app.route('/')
@app.route('/index')
def index():
user = {'username': 'Miguel'}
stuff = []
stuff.append(GetWindowText(GetForegroundWindow()))
return render_template('index.html', title='Home', user=user, stuff = stuff)
if __name__ == "__main__":
app.run(debug=True)
Here is my index.html :
<html>
<head>
{% if title %}
<title>{{ title }} - Microblog</title>
{% else %}
<title>Welcome to Microblog!</title>
{% endif %}
</head>
<body>
<h1>Hello, {{ user.username }}!</h1>
<h1>Here: </h1>
{% for item in stuff %}
<p> {{ item }} </p>
{% endfor %}
</body>
</html>
When I flask run
, there is only ever one item in the list. How do I let the program know I want to continue adding more items? I would like to achieve this in the index()
function.
Thank you for your help!