【发布时间】:2012-11-20 10:38:16
【问题描述】:
我有一个 django-compressor 1.2 的 django 1.4.2 应用程序,用于压缩更少的文件。
我在 app/static/css/home.less 中有我的 less 文件。 它在static/CACHE/css/5208013a00a2.css
下输出一个less文件在本地运行时(Debug=True,文件由 django 提供)我得到了正确的响应。我的 html(模板)文件中的以下输出:
<link rel="stylesheet" href="/static/CACHE/css/5208013a00a2.css" type="text/css">
在部署中运行时(Apache 提供文件)我的响应很糟糕。我的 html 文件中的以下输出:
<link type="text/less" rel="stylesheet" href="/adduplicator/static/css/home.less" charset="utf-8">
文件是在 static/CACHE/css/5208013a00a2.css 下的部署中创建的,所以我假设没有权限问题。我在日志中没有发现任何错误。
settings.py 中的一些设置:
COMPRESS_PRECOMPILERS = (
('text/coffeescript', 'coffee --compile --stdio'),
('text/less', 'lessc {infile} {outfile}'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
部署是通过fabric进行的,它在虚拟环境下创建应用程序。
【问题讨论】:
-
我能想到的两件事:您的
lessc编译器在服务器上可用吗?其次,您的生产和开发设置之间是否存在差异? -
你说对了一部分。 lessc 不可用。通过: sudo apt-get install npm 安装它; sudo npm install less -g。但是,这仍然没有帮助。设置之间的区别是调试真和调试假。一个提供静态文件,另一个不提供
-
Apache 需要配置为提供静态文件。 Django 不会对
DEBUG=False执行此操作,因为内置服务器对静态文件的性能不是很好。 -
@MichaelMior 不相关。与其他 js 一样,css 文件也很完美。它正在使用 mod_wsgi。
-
@GalBracha 啊,好吧。那就别管我的评论了:)
标签: django less django-compressor