【发布时间】:2021-04-08 04:45:26
【问题描述】:
我有一个 html 格式的绘图可视化('viz.html')。我使用 Flask 的 url_for() 语法将它嵌入到我的网页中,并引用了静态文件夹:
<iframe id="igraph" scrolling="no" style="border:none;" seamless="seamless" src="{{ url_for('static', filename='viz.html') }}" height="400" width="120%"></iframe>
它部署没有问题。但是,我的“viz.html”会经常被重写,用新的数据点更新自己。 control + R 或网页刷新不会显示更新的可视化效果。如果我按control + F5 并刷新缓存,则会显示更新的可视化。
我希望用户能够看到更新后的可视化,而无需手动刷新缓存。到目前为止,我已经尝试过:
在“静态”文件夹中检测到文件更改时重新加载烧瓶应用 (Reload Flask app when template file changes)
check_folder = './static'
check_files = []
for dirname, dirs, files in os.walk(check_folder):
for filename in files:
filename = os.path.join(check_folder, filename)
check_files += [filename]
app.run(debug = True, extra_files = check_files)
在 html 页面上禁用浏览器缓存 (http://cristian.sulea.net/blog/disable-browser-caching-with-meta-html-tags)
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
在 Flask 缓存中禁用 Python
resp.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
resp.headers["Pragma"] = "no-cache"
resp.headers["Expires"] = "0"
想知道,我正在尝试做的事情是否可能?
如果可能的话,我该怎么做?建议赞赏!
【问题讨论】: