Replies: 3 comments 1 reply
-
Moving issues to discussions doesn't fix the issues. This is a bug that needs to be fixed. It breaks the library beyond usability. |
Beta Was this translation helpful? Give feedback.
-
Flask does not have an “undocumented cache.” If you are serving a static file with Flask and the development server, it is possible that it is sending a cache-control header. You can try setting the SEND_FILE_MAX_AGE_DEFAULT config key to 0 and see if that helps, though you have noted you've disabled caching at the browser level. Additional troubleshooting steps:
You have not demonstrated a bug. You have not shared any code, let alone a minimally reproducible example. It is far more likely that this is an issue with how you have coded or configured your app. |
Beta Was this translation helpful? Give feedback.
-
For anyone interested in actual solution, its not a bug, template reloading is disabled when If you need template reloading with turned off debug mode, you can explicitly enable it with Minimal working example (tested on Flask 2.3.2, Python 3.10.1, Windows).: from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
app.config["TEMPLATES_AUTO_RELOAD"] = True
app.run(debug=False) This correctly reloads the template if it is changed and the page is refreshed in browser. If template autoreloading is disabled, you need to restart the Flask server to load new changes in templates. |
Beta Was this translation helpful? Give feedback.
-
I've got an HTML file being served from Flask as an iframe that is set to reload every 3 seconds. This is because I modify the file externally to Flask, but from the same python file that initiates Flask. I had what I thought was a great working program. I've finally squashed every bug and undesired function in my code that I've come across, so I figured lets make sure it works without debug mode. I turned it off, and started to use the program. Everything seemed ok for a little while, so I promptly forgot that it was no longer in debug mode. Then I started noticing strange things. Certain functions were being called via manual browser reloads that had not been previously called due to browser reloads. Then the big one: Somewhere, Flask has an undocumented cache. That file that reloads every 3 seconds keeps loading the same version of the file despite being changed. The file that I can open and inspect on my computer shows the expected changes to the file. The file that Flask sends to my browser does not. I tried other browsers. I cleared browser and Windows caches. I tried changes to the code. I tried restarting the program. I tried closing the command line. I googled, I overflowed my stacks. I checked my system processes for multiple copies of Python and flask running when I thought they were closed, etc. Nothing. I go back to debug mode and suddenly, it works again.
TLDR; Flask serves old versions of updated HTML files repeatedly if debug mode is turned off. No amount of reloading or cache clearing will get the updated file.
I'm not exactly sure how to replicate the bug, but I presume the circumstances involve having an "externally" modified HTML file inside the template folder, turn off debugging mode, reload the browser a few times and look for changes to the browser processed HTML output compared to the source of the actual file. Looking at page source from within the browser will of course show the cached version's source. Use Notepad++ or something to look at the actual file that should be served.
When I have every single cache disabled or cleared, I expect the new version of the HTML file to be served to my browser.
Environment:
Beta Was this translation helpful? Give feedback.
All reactions