I'm building a web app. All the external links worked in my Project directory worked fine before but I noticed that yesterday every time I modify the .css file it didn't render this change at all. It actually is freezed with the same style regardless if I even erase the whole .css file content.
This is the response that I'm getting when I run flask:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 230-950-485
127.0.0.1 - - [09/Mar/2017 17:53:09] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2017 17:53:10] "GET /static/css/main.css HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2017 17:53:10] "GET /static/js/main.js HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2017 17:53:10] "GET /static/css/main.css HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2017 17:53:14] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [09/Mar/2017 17:54:04] "GET / HTTP/1.1" 200 -
Notice the 304, seems like that might be the problem? I appreciate any advice in what steps to take.
HTTP response 304 is for "Redirection to a previously cached result". This means Flask is telling your browser that it already has the content. Clear your Browser cache and you will notice that Flask returns a 200 on your next request.
CSS stylesheets are considered static files. There is no interaction with their code, like there is with HTML templates. Therefore, flask has reserved a separate folder where you should put static files such as CSS, Javascript, images or other files. That folder should be created by you and should be named static.
When handling external CSS files with Flask, create index.html at templates folder, and create CSS file at static/css folder, then import CSS file from index.html. Folder name of templates and static are auto included by default settings (possible to change), templates and static folders name should be good, unless you have a specific reason.
The 304 status code can be due to a problem on either the server-side or the client-side, so it might take some troubleshooting in order to diagnose and resolve it. The methods you can use to resolve an HTTP 304 status code vary from simple to fairly technical.
Flask allows us to make a python file to define all routes and functions. In app.py we have defined the route to the main page (‘/’) and error handler function which is a flask function and we passed 404 error as a parameter.
If the browser copy is outdated, meaning that the file has been modified since the last request, it sends an HTTP 200 code and a new copy is used. Unfortunately, there are a few issues that might cause an HTTP 304 response when it’s not supposed to occur.
In Flask this is very common, whether you use Internal or external files:
304 NOT MODIFIED
A conditional GET or HEAD request has been received and would have resulted in a 200 OK response if it were not for the fact that the condition evaluated to false.
In other words, there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation; the server is therefore redirecting the client to make use of that stored representation as if it were the payload of a 200 OK response.
This means Flask is telling the browser that it already has the content.
If you clear your browser cache and you will notice that Flask returns a 200 on your next request.
Disabling cash solutions for this issue is not working for me. If it doesn't update the file because it already represented, it means if i have new code in my file, i will never be able to push these modifications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With