我想知道如何让Django Compressor在Windows上使用LessCSS.
lessc已安装
C:\>lessc
dotless Compiler 1.1.0.7
Compiles .less files to css files.
Run Code Online (Sandbox Code Playgroud)
Django管道设置
COMPRESS_PRECOMPILERS =(('text/less','lessc {infile} {outfile}'),)
我在django面临一个奇怪的问题.我正在使用django-compress app.直到调试才是真的一切都好.当我执行debug = False时,我遇到内部服务器错误问题,如果是404,页面没有js和css,如果没有404.最糟糕的部分是,在控制台上我得到以下错误
UncompressableFileError:'css/default.css'不能通过COMPRESS_URL('/ static /')访问,也无法压缩[16/Jul/2012 17:17:05]"GET /static/img/favicon.ico HTTP/1.1"500 59
像这样它显示每个GET请求500,可通过/ static /访问
所以现在没有获得js和css的理由很清楚.但是在404页面上出错的原因尚不清楚.
即使我尝试禁用和启用django-compress,但启用甚至普通页面时显示404错误
请告诉我导致所有/静态/事物500错误的原因以及为什么404页面会导致内部服务器错误.
我正在使用django-compressor来压缩css文件.
我按照http://django-compressor.readthedocs.org/en/latest/quickstart/中的解释做了.
我更改了我的模板文件,如下所示:
{% load staticfiles %}
{% load compress %}
<!DOCTYPE html>
<html lang="en">
<head>
{% compress css %}
<link href="{% static "crsq/css/zippednewsapp/bootstrap.readable.min.css" %}" rel="stylesheet">
<link href="{% static "crsq/css/zippednewsapp/zippednewsapp.css" %}" rel="stylesheet">
<link rel="stylesheet" href="{% static "crsq/css/zippednewsapp/typeahead.css" %}"/>
{% endcompress %}
</head>
.....
Run Code Online (Sandbox Code Playgroud)
我没有看到任何变化.没错.文件未压缩.我该如何改变?
在我的设置文件中:
DEBUG = False
TEMPLATE_DEBUG = False
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助.谢谢
尝试使用whitenoise和django-compressor将Django应用程序部署到Heroku .
使用DEBUG = False和将其部署到生产中,COMPRESS_ENABLED = True可以毫无问题地访问我的所有静态资产.但是,所有压缩文件都返回404,例如:
http://*.herokuapp.com/static/CACHE/css/fbfaa35dc638.css无法加载资源:服务器响应状态为404(未找到)
启用DEBUG或禁用COMPRESS_ENABLED修复问题,但当然不是我想要的.
我也在设置STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage',但改变这一点并没有帮助.
某些设置(注意我有例如设置目录base.py,local.py等等.这就是为什么我需要一个额外../的路径):
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '../staticfiles')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
Run Code Online (Sandbox Code Playgroud)
在我的基本模板中:
{% compress css %}
<link rel="stylesheet" href="{% static 'css/app.css' %}">
{% block css %}{% endblock %}
{% endcompress %}
[...]
{% compress js %}
<script src="{% …Run Code Online (Sandbox Code Playgroud)