django的HTML第零行错误,Django Compressor命令错误:呈现文件/path.html时出错:类路径“css”无效...

长孙知
2023-12-01

我想用

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压缩

.

我也试过第一次跑步

python manage.py collectstatic

但在

docs

似乎提到了这个错误

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',

)

base.html

我有的模板

{% load compress %}

{% load staticfiles %}

{% load static %}

{% compress css file %}

{% endcompress %}

{% compress js file %}

{% endcompress %}

 类似资料: