2

I have a static css file called blog.css, and I load it in my base.html template like this:

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'css/blog.css' %}">

But when I wanted to change something in that css, the changes doesn't appear. Due to my confusion, I tried to test some things.

  1. renaming blog.css to blog2.css

The weird part is, when I make changes to blog2.css, and called it in the base.html, my changes work, such as changing the background color, and etc.

but when I make changes to blog.css, nothing happens.

So, I tried to DELETE blog.css, but still called it in the base.html.

everything still works when I first made that file. I'm supposed to be expecting a broken designed HTML page and a 404 in the console because the blog.css in the static folder cannot be found.

It's like the blog.css is a ghost or something that is still here in my folder somewhere.. or am I missing something?

I also tried restarting the runserver command, refreshing the page countless times, and even restarting my computer.

I'm quite new to Django and I'm trying my best to understand it, and any help given is appreciated. Thank you very much!

Ken Flake
  • 521
  • 5
  • 23
  • 1
    Do you see the .css file load in the Network tab of Chrome? – JacobIRR Dec 31 '17 at 04:57
  • Yes, mysteriously, it does show up in the Network tab of Chrome.. – Ken Flake Dec 31 '17 at 05:01
  • try to do some research on yourself, your question has nothing to do with django or python, it's just basic rule to clean up browser while designing to reflect changes, or set browser to not to store cache – Gahan Dec 31 '17 at 05:54
  • 1
    As a web developer always use Ctrl + F5! – Klaus D. Dec 31 '17 at 06:07
  • In Mac, if you hold the refresh button down, an option to clear cache will appear. Better yet, keep the "disable cache" box checked while using the dev tools window to be sure you're up to date. – JacobIRR Dec 31 '17 at 14:28
  • In situations like this, it's often helpful to consult [this site](http://shouldiblamecaching.com). – Don't Panic Dec 31 '17 at 21:53
  • Please choose an answer that provides the best solution to your problem, and click the green check mark ✅ to mark it as accepted. (Can be either yours' or any of the other two) – abccd Jan 02 '18 at 05:03

4 Answers4

6

to test the changes of css or js or any such static files follow any preferred approach listed below

Simple way of approach:

  • Refresh tab by pressing (Ctrl + F5) instead of only using F5
  • Open private window or incognito window and run the website
  • Clear browser cache
  • Try to use different browser (prefer a browser which wasn't used to open the site or having cache of the site)
  • Disable Cache while developer tools are open: follow steps in this answer
Community
  • 1
  • 1
Gahan
  • 3,616
  • 4
  • 17
  • 38
  • Ctrl + F5 works like a charm because it does remove the cache when refreshing. I didn't know that until now. Thank you! – Ken Flake Feb 02 '18 at 06:59
3

That happened to me before, it just took time and reloading the server for the changes to occur, try changing your browser to see if the CSS is gone by now. Django uses caching in browsers to load faster. To resolve the problem you must clear the cache.

Ryan
  • 123
  • 3
  • 11
2

I fixed it by clearing the cache in my browser. The blog.css from the cache is not found anymore.

Jean-François Corbett
  • 34,562
  • 26
  • 126
  • 176
Ken Flake
  • 521
  • 5
  • 23
  • The way Python Django work is that it cache data to make content and page load faster. To prevent this from happening again is by clear cache before the server is run each time or disabling cache – Ryan Dec 31 '17 at 05:43
0

As mentioned in other answers, the "cache files" seem to be the problem. Try removing the cache (I haven't tried this).

You could also change the name of the CSS file to something other than the old name. This worked for me.

cigien
  • 50,328
  • 7
  • 37
  • 78