我正在使用 django-compressor 来压缩我的 css,所以我接下来用 HTML 编写:
{% load compress %}
{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}styles/blueprint/reset.css" media="all" />
<link rel="stylesheet" href="{{ STATIC_URL }}styles/base.css" media="all" />
<link rel="stylesheet" href="{{ STATIC_URL }}styles/header.css" media="all" />
<link rel="stylesheet" href="{{ STATIC_URL }}styles/footer.css" media="all" />
<link rel="stylesheet" href="{{ STATIC_URL }}styles/frontpage.css" media="all" />
<link rel="stylesheet" href="{{ STATIC_URL }}styles/about.css" media="all" />
{% endcompress %}
它给出了以下错误:
500 page with:
UncompressableFileError: 'styles/blueprint/reset.css' isn't accesible
via COMPRESS_URL ('/media/static/') and can't be compressed
顺便说一句:所有文件都在静态路径中,所以如果我评论压缩它们将起作用。
我的 settings.py 关于压缩:
COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_CSS_FILTERS = ['compressor.filters.csstidy.CSSTidyFilter', 'compressor.filters.css_default.CssAbsoluteFilter']
COMPRESS_CSSTIDY_BINARY = '/usr/bin/csstidy'
COMPRESS_CSSTIDY_ARGUMENTS = '--template=highest --remove_last_;=true --sort_properties=false --sort_selectors=false --merge_selectors=1'
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_URL = STATIC_URL