django-compressor给文件找不到,但它就在那里

时间:2012-06-22 07:12:06

标签: css yui-compressor django-compressor

我正在使用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

2 个答案:

答案 0 :(得分:3)

我遇到了类似的问题,您是否使用RequestContext将模板渲染为context_instance?

E.g:

def some_view(request):
    ...
    return render_to_response(... , context_instance=RequestContext(request))

答案 1 :(得分:1)

我有同样的问题。我不知道为什么,但我的解决方案是删除参数--remove_last_;=true