烧瓶图像未在html页面上更新

时间:2018-01-10 05:39:56

标签: python flask url-for

我有烧瓶网络应用程序,用户可以上传图像和显示直方图 我将直方图图像保存在静态文件夹中,并在用户尝试使用新图像时将其删除

@app.route('/upload', methods=['POST'])
def upload():
    file = request.files['file']
    filename = secure_filename(file.filename)
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

    os.remove('./static/h_hist.png')
    hsv_hist.histogram(filename)
    return render_template("result.html", filename=filename)

如果用户上传

,新图像的直方图已保存到静态文件夹中

但是当我在我的页面上显示时,直方图图像不会改变为新图像的直方图 它仍然是旧的

  

result.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Image Processing Result</title>
</head>
<body>
<div class="container">

        <img src="{{ url_for('static', filename=filename) }}">
        <h2>HSV Histogram</h2> <hr>
        <img src="{{ url_for('static', filename='h_hist.png') }}">
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果文件名没有改变并且图像本身被删除,则图像很可能被broswer缓存,除非文件名发生变化或缓存过期,否则不会更新。

您可以使用浏览器开发工具进行检查,并查看是否在网络选项卡下获取了图像的代码304。

这个答案显示了如何处理cahing:Browser caching issues in flask

替代方法是只更改文件名。