我正在使用 Django-Compressor Filter 作为 Wagtail 的一部分(具有超酷 UI 的 Django 变体 CMS)。环境是 Wagtail 0.2 + Python 2.7 + Django 1.6 + Virtualenv + FastCGI + Apache 共享主机。
尝试访问 CMS 的管理/登录页面时出现问题。Django 显示错误呈现模板
Error during template rendering
In template /home/username/env/lib/python2.7/site-packages/wagtail/wagtailadmin/templates/wagtailadmin/skeleton.html, error at line 20
/bin/sh: django_libsass.SassCompiler: command not found
Skeleton.html 的第 20 行是:
<!doctype html>
{% load compress %}
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <!--<![endif]-->
<title>Wagtail - {% block titletag %}{% endblock %}</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
{% block css %}{# Block defined for timing breakdowns in django debug toolbar - not expected to be overridden #}
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" />
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Bitter:400,700" />
19
20 {% compress css %}
21 <link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/normalize.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/vendor/jquery-ui/jquery-ui-1.10.3.verdant.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/vendor/jquery.timepicker.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/core.scss" type="text/x-scss" />
{% endcompress %}
{% block extra_css %}{% endblock %}
{% endblock %}
</head>
<body class="{% block bodyclass %}{% endblock %} {% if messages %}has-messages{% endif %}">
我的settings.py中的预编译器,DEBUG设置为True:
COMPRESS_ENABLED = True
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
试错 #1
我尝试更改为:
('text/x-scss', '/home/username/env/lib/python2.7/site-packages/django_libsass {infile} {outfile}')
但这导致我出现字典更新序列元素 #0 错误。
我已经安装了 django_libsass 和压缩器,还尝试了, , pip install libsass
, ngm install lessc
turn pip install sass
, added , added其他类似问题中的建议。运行返回相同的错误。DEBUG = False
COMPRESSOR_OFFLINE
COMPRESSOR_ENABLED
manage.py compress
已经重新检查并且站点包和 django_libsass 确实在我的 sys.path 上
SassCompiler 可以在~/env/lib/python2.7/site-packages/django_libsass.py
试错#2
重新检查sass
是否已安装并在我的路径上。
将代码更改为:
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --scss {infile} {outfile}'),
)
返回错误:
Exception Type: FilterError
Exception Value:
/bin/sh: sass: command not found
试错#3
阅读此feedly 问题后,尝试 pip install compass
无效
试错#4
根据 gasman 的评论,我运行了 python manage.py shell 并尝试导入 SassCompiler 它没有错误。
Python 2.7.6 (default, Nov 11 2013, 18:34:29)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django_libsass import SassCompiler
>>>
完整回溯
如果这个问题太长,我深表歉意。
Traceback:
File "/home/username/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
139. response = response.render()
File "/home/username/env/lib/python2.7/site-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/username/env/lib/python2.7/site-packages/django/template/response.py" in rendered_content
82. content = template.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render
840. bit = self.render_node(node, context)
File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
78. return node.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
123. return compiled_parent._render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render
840. bit = self.render_node(node, context)
File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
78. return node.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
62. result = block.nodelist.render(context)
File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render
840. bit = self.render_node(node, context)
File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
78. return node.render(context)
File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render
147. return self.render_compressed(context, self.kind, self.mode, forced=forced)
File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render_compressed
107. rendered_output = self.render_output(compressor, mode, forced=forced)
File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render_output
119. return compressor.output(mode, forced=forced)
File "/home/username/env/lib/python2.7/site-packages/compressor/css.py" in output
51. ret.append(subnode.output(*args, **kwargs))
File "/home/username/env/lib/python2.7/site-packages/compressor/css.py" in output
53. return super(CssCompressor, self).output(*args, **kwargs)
File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in output
246. content = self.filter_input(forced)
File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in filter_input
194. for hunk in self.hunks(forced):
File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in hunks
169. precompiled, value = self.precompile(value, **options)
File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in precompile
226. **kwargs)
File "/home/username/env/lib/python2.7/site-packages/django_libsass.py" in input
51. return compile(filename=self.filename)
File "/home/username/env/lib/python2.7/site-packages/django_libsass.py" in compile
41. return sass.compile(**kwargs)
Exception Type: AttributeError at /admin/login/
Exception Value: 'module' object has no attribute 'compile'