Django won't refresh staticfiles

前端 未结 15 1111
渐次进展
渐次进展 2020-12-07 18:31

This is annoying. I have a javascript file referenced on a django template:

 
15条回答
  •  离开以前
    2020-12-07 19:10

    One solution is to change the settings to the following:

    STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
    

    What this does is create a copy of the static file with a content hash in the file name (when running collectstatic). This way when the contents are changed the filename is changed and the old cache won't be used. The only problem with this is it doesn't get used when in DEBUG = True mode so you have to do a shift-reload to do a hard reload.

    You can read the docs on ManifestStaticFilesStorage for more info.

    EDIT: I found a solution for making sure static files are not cached in dev and posted it on another question.

提交回复
热议问题