Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django CSS not updating

Tags:

css

django

I have this code to refer to my CSS script in my base.html for my Django project:

<link href="{% static 'css/project.css' %}" rel="stylesheet"> 

The problem is that whenever I add or remove styling from project.css, it doesn’t update when I run the server.

I know this happens because every time the page loads the browser cache will think it’s seen the file before and reload the cached version from disk. I also know a solution is to change the CSS filename every time I make an update.

Is there an easier way to reload the CSS file every time I refresh my browser?

like image 441
Kartikeya Sharma Avatar asked Oct 06 '18 19:10

Kartikeya Sharma


People also ask

Why my CSS changes are not reflecting in Django?

Your browser may be caching the css files within the browser, preventing the changes from being loaded. Try doing a “full” page refresh. On Windows in either Chrome or Firefox, hold down either the shift or ctrl key and click on the reload icon (the “circle arrow”), or do a ctrl-F5 (reload key).

Why are my CSS changes not reflecting?

Browser Cache If you are adding/modifying in-line CSS or JavaScript and not seeing the changes reflected in the HTML source, the page is likely being cached. The solution may be to purge the WordPress object cache, which stores our page caching (Batcache) renders.

Does CSS work with Django?

Including CSS in Django TemplateWe need to load the static files by adding the below line of code at the top of the template (. HTML) file. Then, insert the stylesheet in the HTML using link HTML tag. If you are new to the HTML and CSS, you can learn more about adding CSS in HTML code.


2 Answers

You can bypass the cache using ctrl + F5

for detailed reference: https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache

like image 54
Abhijith K Avatar answered Sep 19 '22 05:09

Abhijith K


You have to click on Ctrl + f5 every time to update your CSS, which isn't dope. You can actually do something like this:

<link rel="stylesheet" href="/static/css/mycss.css?{% now "U" %}"/> 

The {% now "U" %} will generate a random timestamp which updates your CSS every time you reload the page. I hope this works.

For better understanding check out: click here

like image 44
Xamuel San Avatar answered Sep 20 '22 05:09

Xamuel San