3

I have flask web app that user can upload image and display histogram i save my histogram image in static folder and delete it when user try to up new image

@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)

histogram of new image have been save into static folder if user upload

but when i display it on my page the histogram image don't change to histogram of new image it is still the old one

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>
davidism
  • 121,510
  • 29
  • 395
  • 339
Avause
  • 61
  • 3
  • 7

1 Answers1

0

If the filename doesn't change and the image itself is deleted then the image is most likely being cached by the broswer and not updated unless the filename changes or the cache expires.

You can check it using the browser dev tools and looking if you get code 304 for the image under networking tab.

This answer shows how to deal with cahing: Browser caching issues in flask

Alternative is to just change the filename.

Erlend
  • 33
  • 6