Python Flask Not Updating Images [duplicate]
This seemed to work
Using Flask, how do I modify the Cache-Control header for ALL output?
Did it by adding:
app = Flask(__name__)app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
To the top (included the app = Flask part to help other newbs) and this at the end:
# No caching at all for API endpoints.@app.after_requestdef add_header(response): # response.cache_control.no_store = True response.headers['Cache-Control'] = 'no-store, no-cache, must- revalidate, post-check=0, pre-check=0, max-age=0' response.headers['Pragma'] = 'no-cache' response.headers['Expires'] = '-1' return response
This works, but the log in my command prompt window is constantly sending information.
try to change the image name so it seems it pretends to be a new image every time you regenerate it. You can use some time-based suffix of the file name. Or you can just change the url of the image adding some fake get parameters to it.
Reference:flask cache busting
Had the same problem and using local hour as name extension worked just fine for me. Some thing to note here are:
- The ":" character in the timestamp needs to be replaced since it is not accepted in naming conventions.
- You will have to return a list of all the files in the static folder when rendering the template in flask.
- You will have to iterate through that list in html with jinja code to find the naming patterns you inserted in the picture names.