首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django-压缩器CommandError:在呈现文件/ path .path:无效的类路径'css‘时发生错误

django-压缩器CommandError:在呈现文件/ path .path:无效的类路径'css‘时发生错误
EN

Stack Overflow用户
提问于 2018-06-19 00:44:36
回答 1查看 1.3K关注 0票数 1

我正在尝试在我的项目中使用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 10Django==2.0.5django-compressor==2.2

相关的settings.py部分如下

代码语言:javascript
复制
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标记中

代码语言:javascript
复制
{% 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 %}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-19 00:51:06

您必须定义COMPRESS_FILTERS而不是COMPRESS_CSS_FILTERS,因为后者只是前者的css键的一个向后兼容别名。也就是说,您的配置应该是:

代码语言:javascript
复制
COMPRESS_FILTERS = {
    'css': ['compressor.filters.css_default.CssAbsoluteFilter'], 
    'js': ['compressor.filters.jsmin.JSMinFilter']
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50919182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档