html – Updating an image on the web using Python and Flask-ThrowExceptions

Exception or error:

I have a basic question regarding Python and Flask for web development.

In my html template file, I have a line to display an image, shown as below:

<img width="600" height="451" src="static/graph_1.png">

The image is in the static folder. When I update this image but using the same name ‘graph_1.png”, the web still shows the old image, not the updated one. I think the browser somehow remembers the old image with the same name. But I didn’t really want to change the name of the image. I learned it has something to do with “Catche-Control”? Please advice on how I can solve this problem. Thanks in advance!

How to solve:

User cmd+shft+r on mac or ctrl+shift+r on a pc to load the page without using cache.

off topic, but you might want to look into the flask documentation on templates. A better approach to adding the path to the html is using jinja to inject the path. The nice thing about this is if you ever change the file structure, as long as the file name remains the same you’re golden!

<img width="600" height="451" src="{{ url_for('static', filename='graph_1.png' }}>

You can find more info here

Leave a Reply

Your email address will not be published. Required fields are marked *