Django压缩程序不缩小文件

2024-05-16 22:05:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让django压缩机和夹层一起工作。 对于第一次尝试,我只是简单地安装了django压缩器(对于夹层应该这样做),并更改了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指向缓存中的文件,如下所示:

<link rel="stylesheet" href="/static/CACHE/css/16e8b98f5bd3.css" type="text/css" media="screen">

但这些文件并没有缩小,django compressor只是复制了它们并更改了名称。 你知道为什么压缩机不把它们缩小吗?


Tags: appsdjangopyhtmlpagescontribcompressor压缩器
2条回答

即使使用DEBUG = False,Django压缩器也不会在Django服务器上运行。默认情况下,它只会将所有css文件合并为一个。要做其他事情,如缩小你可以应用过滤器。这是我在设置中所做的

COMPRESS_ENABLED = True
COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter',  'compressor.filters.cssmin.CSSMinFilter']

我想这对其他人会有帮助的。干杯!

问题是memchached,禁用它,Django显示了权限问题,要缩小css,我必须选择一个类似compressor.filters.cssmin.cssmin filter的过滤器

相关问题 更多 >