5

I'm having a css file and i want to modify it to fit my needs. The problem is that it seems to be cached somewhere, as i just cannot see the changes, no matter what i do in the css file. I am sure i am pointing to the right file, as by now i'v modified in it, and it worked. Is there any setting so that i can turn the cache off? Thanks!

2
  • 1
    Which browser are you using? Blow out your cache. Commented Jul 6, 2010 at 17:31
  • did you perform "python manage.py collectstatic" command? Commented Feb 23, 2022 at 17:33

4 Answers 4

8

As pointed out in this article http://www.wkoorts.com/wkblog/2009/07/12/css-auto-reload-with-django-templates/, you could force django reload your css file by using a parameter in your css link :

<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?{% now "U" %}" />

This is a timestamp which takes a different value every second, so you could even reload your css second every second if needed!

Sign up to request clarification or add additional context in comments.

1 Comment

More common way is to use something like .../style.css?version=1 and increment the version every time you make a change
7

Just go into your site, view source, and copy the link to your CSS file. Verify the link, verify it's being modified. Refresh the CSS file manually via your browser to get the latest.

This isn't a Django issue.

Comments

0

Did you try appending a datetime stamp to the end of the request? I know some frameworks do this to .js and .css files automatically to prevent caching.

1 Comment

it is not a .css added as a MEDIA parameter to a view.
0

Instead of using complicated solutions you can add extra parameter to your includes in the templates.

For static includes:

<script src="{% static 'js/polls/polls.js' %}?version=1"></script>

For direct includes:

<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?version=1" />  

Note the ?version=1 in the code. Every time you're modifying the file, change this version in the template, so browser will be forced to reload the file.

Of course you can use even now as suggested by @rom, but if your static files are not being changed very often, it's not the smartest idea to don't use cache at all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.