0

The problem that I have is not I fail to load css file, is that I can't update them. The first few times I edit after I have just created my css files, the changes were working. But after a while, when I try to change for example: the color, it is not changing. The colour on the web is not changing and I click to see the source file, it is using the unchanged version. I have also tried to use python manage.py collectstatic but still can't update the file.

# in settings.py 
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# in main urls.py 
if settings.DEBUG: 
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 
3
  • 2
    have you tried to empty your cache/private navigation? Commented Jan 2, 2020 at 15:17
  • 1
    First, remove the static urls in urls.py. They are not needed if you added "django.contrib.staticfiles" to your INSTALLED_APPS setting. Second, please check in your browser developer tools, network tab, what the response headers are for the HTTP request for your css file. And report back here. Commented Jan 2, 2020 at 15:20
  • did you try opening in a incognito browser and check ? Commented Jan 2, 2020 at 16:29

2 Answers 2

1

I had this problem the other day... My issue was because the css was being cached and the cached version was being used rather than the new version.

Check what the status code of the CSS being loaded is, if you're just running a dev server with "manage.py runserver" then the status code is the first number after the "GET " output.

If the status code for your css is 304 then it is being cached. Alternatively in Chrome and Firefox (probably other browsers too but they're what I use) open then Dev tools (Ctrl+Shift+I) and go to the "Network" tab. When you reload the page if the size of your css is listed as "(memory cache)" then a cached version is being used.

To reload the page loading the new css you need to reload the page without using the cache, for Chrome and Firefox you can do Ctrl+Shift+R, the status code for your CSS should then show as 200.

To make it easier, what I did (in Chrome), is open then Dev tools (Ctrl+Shift+I) and click the "Network" tab and check the "Disable cache", this forces the site to load all static files (including the css) from the server everytime rather than using the cached version.

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

2 Comments

No, it is 200. [02/Jan/2020 22:14:57] "GET /static/blog/style.css HTTP/1.1" 200 363
And if I use other ports for example python manage.py runserver 8899 to run after I have edited the css file. The changes are working, and I don't know why.
0

On mac, press shift then reload the page. It's working.

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.