简体   繁体   English

如何更改 Django 静态文件

[英]How to change Django static files

I know this might be a really obvious question, but I'm doing a Django project where I have Javascript in my static files.我知道这可能是一个非常明显的问题,但我正在做一个 Django 项目,我的静态文件中有 Javascript。 However, I have noticed that whenever I make a change to those files, my web server doesn't reflect the changes.但是,我注意到每当我对这些文件进行更改时,我的 Web 服务器都不会反映这些更改。 Is there some migration or something else I need to do to make my web server reflect changes to my static Javascript files?是否有一些迁移或我需要做的其他事情来使我的 Web 服务器反映对我的静态 Javascript 文件的更改? Thanks.谢谢。

You might want to run python manage.py collectstatic on the webserver to put the static files in the correct folder.您可能希望在网络服务器上运行python manage.py collectstatic以将静态文件放在正确的文件夹中。 https://docs.djangoproject.com/en/3.1/howto/static-files/ https://docs.djangoproject.com/en/3.1/howto/static-files/

Another possible issue is caching.另一个可能的问题是缓存。 You could use ManifestStaticFilesStorage https://docs.djangoproject.com/en/3.1/ref/contrib/staticfiles/#manifeststaticfilesstorage to have new filenames whenever a file is updated and escape cache issues.您可以使用 ManifestStaticFilesStorage https://docs.djangoproject.com/en/3.1/ref/contrib/staticfiles/#manifeststaticfilesstorage在文件更新时使用新文件名并逃避缓存问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM