Django Compress setup

来源:互联网 发布:淘宝直通车养词要多久? 编辑:程序博客网 时间:2024/05/23 12:58

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

0 0