Django的CachedStaticFilesStorage不是散列文件URL

2024-10-01 11:37:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想对我的一些javascript和css文件进行版本控制,因为我在网站上工作时遇到了缓存问题。我在django1.6中读到了cachedstaticfilestorage,它看起来很完美。我修改了我的设置.py设置如下:

STATIC_ROOT = 'staticfiles'

STATIC_URL = ''

# Additional locations of static files
STATICFILES_DIRS = (
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

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

作为测试,我重写了最有问题的css标记,看看它是否会开始散列文件路径。相反,每当我尝试加载页面时,都会出现500个错误。在

你知道我哪里出错了吗?我还错过了一个步骤吗?在

模板中的条目:

^{pr2}$

Tags: 文件djangopyurl网站staticrootjavascript
2条回答

很狡猾。。。如果你仔细阅读这些文件,你会学到:

... use the staticfilesstatic template tag to refer to your static files in your templates ...

所以不是:

{% load static %}

使用

^{pr2}$

这在Django 1.10中已修复,如documentation中所述:

In older versions, you also had to use {% load static from staticfiles %} in your template. The static template tag ({% load static %}) now uses django.contrib.staticfiles if it’s installed.

相关问题 更多 >