我试图让 django-compressor 与夹层一起工作。对于第一次尝试,我只是安装了 django 压缩器(应该为 Mezzanine 做)并更改 DEBUG = False 但从 Django 生成的 HTML 没有任何变化。所以我遵循了 django 压缩器的文档并修改了我的 settings.py:
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
#"django.contrib.staticfiles.finders.AppDirectoriesFinder",
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
"compressor.finders.CompressorFinder",
)
INSTALLED_APPS = (
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.sitemaps",
"django.contrib.staticfiles",
"mezzanine.boot",
"mezzanine.conf",
"mezzanine.core",
"mezzanine.generic",
"mezzanine.blog",
"mezzanine.forms",
"mezzanine.pages",
"mezzanine.galleries",
"mezzanine.twitter",
#"mezzanine.accounts",
#"mezzanine.mobile",
#'debug_toolbar',
"compressor",
)
OPTIONAL_APPS = (
#"debug_toolbar",
"django_extensions",
#"compressor", I commented it to follow the django-compressor doc
PACKAGE_NAME_FILEBROWSER,
PACKAGE_NAME_GRAPPELLI,
)
COMPRESS_ENABLED = True
COMPRESS_ROOT = STATIC_ROOT
这些是安装在我的环境中的软件包:
Django==1.6.5
Mezzanine==3.1.5
Pillow==2.5.1
bleach==1.4
distribute==0.6.24
django-appconf==0.6
django-compressor==1.4
filebrowser-safe==0.3.5
future==0.9.0
grappelli-safe==0.3.12
html5lib==1.0b3
oauthlib==0.6.3
pytz==2014.4
requests==2.3.0
requests-oauthlib==0.4.1
six==1.7.3
tzlocal==1.0
在这里,我如何在模板中使用压缩器:
{% load pages_tags mezzanine_tags i18n future staticfiles compress %}
{% compress css %}
<link rel="stylesheet" href="{% static "css/custom/mycss.css" %}">
{% endcompress %}
在我启动之前什么都没有发生:
python manage.py 压缩 --force
所以现在我已经填充了缓存,并且从 Django 生成的 HTML 指向 CACHE 中的文件,例如:
<link rel="stylesheet" href="/static/CACHE/css/16e8b98f5bd3.css" type="text/css" media="screen">
但是文件没有被缩小,django 压缩器只是复制它们并更改了名称。你知道为什么压缩机不缩小它们吗?