Ken Flake
Ken Flake

Reputation: 595

I deleted a css static file but my website still reads it?

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!

Upvotes: 3

Views: 6782

Answers (4)

SANGEETH SUBRAMONIAM
SANGEETH SUBRAMONIAM

Reputation: 1086

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.

Upvotes: 0

Ryan
Ryan

Reputation: 133

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.

Upvotes: 4

Ken Flake
Ken Flake

Reputation: 595

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

Upvotes: 2

Gahan
Gahan

Reputation: 4213

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

Upvotes: 9

Related Questions