我试图让django-compressor与mezzanine一起使用。 首先,我按照Mezzanine的要求安装了django compressor,并将DEBUG = False更改,但在Django生成的HTML中没有任何变化。 因此,我遵循了django compressor的文档,并修改了我的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 compress --force
现在我的缓存已经填充,来自Django的HTML指向CACHE中的文件,如下所示:
<link rel="stylesheet" href="/static/CACHE/css/16e8b98f5bd3.css" type="text/css" media="screen">
但是这些文件没有被压缩,Django Compressor只是复制并更改了它们的名称。你知道为什么Compressor没有对它们进行压缩吗?
但是这些文件没有经过压缩,Django Compressor只是复制并更改了它们的名称。您知道为什么Compressor没有对它们进行压缩吗?