简体   繁体   English

具有缓存清除功能的Django静态文件

[英]Django staticfiles with cache busting

I'm trying to migrate my project from using {% compress %} to grunt for the whole front-end workflow. 我正在尝试将项目从使用{%compress%}迁移到整个前端工作流程。 I got my grunt setup correctly and I can generate my main.min.css and main.min.js. 我正确安装了grunt,可以生成main.min.css和main.min.js。 With collectstatic I see them copied to the right folder, but when I deploy to staging all I get is a big fat 500 error. 使用collectstatic时,我看到它们已复制到正确的文件夹,但是当我部署到暂存时,我得到的是一个很大的Fat 500错误。

INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
'captcha',
'core',
)

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

STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
)

and in the template: 并在模板中:

<link rel="stylesheet" href="{% static "core/dist/css/main.min.css" %}" />

It works locally if I set DEBUG=False in settings.py (without loading the static files obviously). 如果我在settings.py中将DEBUG = False设置为本地,则它将在本地工作(显然不会加载静态文件)。 Any idea? 任何想法?

For everyone ending up here in the future: check your .gitignore file and be sure to only reference existing files in the template! 对于以后遇到的所有人:检查您的.gitignore文件,并确保仅引用模板中的现有文件!

In my case I had dist/ in my .gitignore and I was storing my static files in core/dist/ so they got gitignored and ended up not being on the server. 在我的情况下,我在.gitignore中包含dist/ ,并将静态文件存储在core / dist /中,因此它们被gitignored并最终不在服务器上。

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

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