So the problem I'm having is that my web app only sometimes loads the css file and it uses the same css file data that was loaded even if I make edits to the css file and even when I delete the file. I have no clue what's going on. I have noticed that when it does load the css correctly the following message is displayed:
127.0.0.1 - - [08/Jun/2015 14:46:19] "GET /static/style.css HTTP/1.1" 200
My style.css
file is under a folder named static
and in my html file I have
<link type='text/css' href='{{ url_for('static', filename='style.css') }}' rel='stylesheet'>
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.
To add template files like HTML, CSS, JavaScript in Flask application, you need to maintain a certain folder structure like below: Crate a folder for HTML files inside your root directory. I am giving name of that folder as “ templateFiles “ Create a folder for static files like CSS, images etc.
To reference the static files using the url_for() function, pass in the name of the directory – static in this case – and the keyword argument of filename= followed by your static file name. Flask automatically creates a static view that serves static files from a folder named static in your application's directory.
The href Attribute href stands for “hypertext reference”. You use it to specify the location of the CSS file and the file name. It is a clickable link, so you can also hold CTRL and click it to view the CSS file. For example, href="styles.
Flask sets cache control headers on static resources, and your browser will cache those files up to 12 hours.
Your options are:
Set the SEND_FILE_MAX_AGE_DEFAULT
configuration directive to a shorter value; it is set to 43200 but you can set it to 0 if you really want to.
Add a cache buster query parameter to your static URLs; if your static URLs end with ?<somerandomvalue>
your browser will reload the resource if that random value ever changes. You could do this by hand each time or you can use this Flask snippet to override the url_for()
function to add such a value for you based on the file modification time.
Use an incognito browser window (private browsing mode in other browsers) to force your browser to ignore the cache for a specific session. Each time you open a new incognito tab or window, the cache should be invalidated for that session.
Please use ctrl + f5
because when you use simple refresh it shows data from cache but when you do ctrl + f5
it render new data
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