我正在尝试在我的项目中使用django-compressor。到目前为止,在我的开发环境中,当我运行python manage.py compress时,我得到了这个错误CommandError: An error occurred during rendering D:path/to/a/template.html: Invalid class path 'css'
我有很多的模板文件分散在许多应用程序。错误随机弹出,每次运行python manage.py compress时指向不同的模板。
我也尝试过第一次运行python manage.py collectstatic,但是没有结果,在文档中似乎没有提到这个错误。
OS: Windows 10,Django==2.0.5,django-compressor==2.2
相关的settings.py部分如下
DEBUG = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_URL = STATIC_URL
COMPRESS_PARSER = 'compressor.parser.HtmlParser'
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_OFFLINE_MANIFEST = 'compressor_manifest.json'
COMPRESS_CSS_FILTERS = {
'css': ['compressor.filters.css_default.CssAbsoluteFilter'],
'js': ['compressor.filters.jsmin.JSMinFilter']
}
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)在我的项目的<head></head>模板的base.html标记中
{% load compress %}
{% load staticfiles %}
{% load static %}
{% compress css file %}
<link rel="stylesheet" href="{% static 'css/fname.css' %}">
{% endcompress %}
{% compress js file %}
<script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'js/fname.js' %}"></script>
{% endcompress %}发布于 2018-06-19 00:51:06
您必须定义COMPRESS_FILTERS而不是COMPRESS_CSS_FILTERS,因为后者只是前者的css键的一个向后兼容别名。也就是说,您的配置应该是:
COMPRESS_FILTERS = {
'css': ['compressor.filters.css_default.CssAbsoluteFilter'],
'js': ['compressor.filters.jsmin.JSMinFilter']
}https://stackoverflow.com/questions/50919182
复制相似问题