Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes made to (static) CSS file not reflecting in Django development server

Tags:

css

django

I am making a Web app using Django and was having some trouble getting the changes made in the CSS file (which is stored in the static directory of my app) to reflect onto the development server.

To be clear the server is able to access static files, however, it is currently stuck on an old iteration of my CSS file. A similar problem had occurred a few weeks ago, when any change I made to the CSS file wasn't showing up. That problem fixed itself after a few days.

However, not getting immediate visual feedback is extremely frustrating. I have tried all of the following to rectify the problem:

  • My DEBUG is set to 'True'
  • I have provided a STATIC_URL
  • I tried 'collecting' the static files. The command worked but the dev server is still not reflecting changes made to the CSS file
  • I provided a STATIC_ROOT, STATICFILES_DIR and STATICFILES_FINDER. Currently these are commented out as I realized some of these are for production only or are unnecessary for development.

My static resources are kept in the 'static' directory of one of my apps -- 'post_it_gen' which is part of the project. According to the documentation this should be automatically searched by Django.

Any new suggestions would be greatly appreciated.

like image 510
Tushar Avatar asked Jul 27 '14 05:07

Tushar


People also ask

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.

Can I load static in CSS Django?

Django will use the first static file it finds whose name matches, and if you had a static file with the same name in a different application, Django would be unable to distinguish between them. We need to be able to point Django at the right one, and the best way to ensure this is by namespacing them.


2 Answers

If you develop locally using Django's server there's no need to use the collectstatic command, it is only meant to collect all static dependencies to a single access point where you can point your 'real' server to, e.g. apache, lighttpd, nginx etc.

As for your problem, you insinuate it 'magically' fixes it self after a few days. Have you tried resetting your browser's cache?

like image 111
Hedde van der Heide Avatar answered Sep 28 '22 04:09

Hedde van der Heide


In my case, my browser was caching the Js and CSS files and thus I was unable to see the changes.
You can try hard refreshing the page
For chrome/chromium browsers:
Ctrl + F5 or Ctrl + Shift + R
both works for me.

like image 43
theshubhagrwl Avatar answered Sep 28 '22 03:09

theshubhagrwl