您的位置:首页 > 编程语言 > Go语言

Django Compress setup

2016-07-04 18:01 507 查看
1. Install Django-Compress

For windows:

a. pipinstall wheel==0.29.0

b.pipinstall rcssmin==1.0.6 --install-option="--without-c-extensions"

c.pipinstall rjsmin==1.0.12 --install-option="--without-c-extensions"

d.pipinstall django_compressor==2.0

For Linux:

a.pipinstall django_compressor==2.0

2.Enable Feature

settings.py

a. append 'compressor.finders.CompressorFinder' to STATICFILES_FINDERS
b. COMPRESS_ENABLED=True (If DEBUG=True, need explicit declaration)

c.COMPRESS_OFFLINE=True (如果希望离线压缩文件,需要手动打开设置)

d.append template variable to COMPRESS_OFFLINE_CONTEXT (因为compress所包含的模板片段可能会有变量,需要显示指定)

eg:

COMPRESS_OFFLINE_CONTEXT = {

    'URL_PREFIX': URL_PREFIX,

    'STATIC_URL': STATIC_URL

}

3.Use Compress

a.{% load compress %}

b.{% compress css %}{% endcompress %}  ( generate .css )

c.{% compress js %}{% endcompress %} ( generate .js )

4.Relative URL
http://django-compressor.readthedocs.io/en/latest/usage/ http://stackoverflow.com/questions/9559018/does-django-compressor-work-with-template-inheritance
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django