【发布时间】:2021-04-01 09:17:22
【问题描述】:
我想通过在其中添加更多“东西”来不断更新我的列表stuff。但是,我的列表没有更新(最好每秒更新一次,但我不知道如何在烧瓶中执行 while 循环)。
这是我的 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)
这是我的 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>
当我flask run 时,列表中只有一项。如何让程序知道我想继续添加更多项目?我想在index() 函数中实现这一点。
感谢您的帮助!
【问题讨论】:
标签: python html python-3.x flask while-loop