Django Compressor不在生产中工作

时间:2015-05-10 16:34:24

标签: python django django-compressor

我想使用django_compressor,但它在我的生产环境中无效。

在开发中(DEBUG=True),它正在工作并创建.sass-cache& CACHE个文件夹。

我的settings.py

DEBUG = False
TEMPLATE_DEBUG = False
INSTALLED_APPS = (
    ...,
    'django.contrib.staticfiles',
    'compressor',
    'myapp',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'com.app.static')↲
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)
COMPRESS_ENABLED = True
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
MEDIA_URL = '/media/'

scss文件将模板目录放在app上。

{% load staticfiles %}
{% load compress %}
<html>
<head>
    {% compress css %}
        <link rel='stylesheet' type='text/scss' href="{% static 'top/css/top.scss' %}" charset='utf-8'>
    {% endcompress %}
</head>
</html>

2 个答案:

答案 0 :(得分:4)

将此添加到settings.py

COMPRESS_OFFLINE = True

并压缩

python manage.py compress

答案 1 :(得分:-1)

快速浏览文档可以看出答案: http://django-compressor.readthedocs.org/en/latest/settings/

django.conf.settings.COMPRESS_ENABLED应该设置为True,否则它与DEBUG相反

<强>更新

很抱歉,我完全错过了您的设置: COMPRESS_ENABLED = True