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
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中使用jquery ajax post数据出现403错误的解决办法(两种方法)
- django使用ajax post数据出现403错误如何解决
- windows+apache+mod_python配置django运行环境
- python Django连接MySQL数据库做增删改查
- django自定义Field实现一个字段存储以逗号分隔的字符串
- Django框架利用ajax实现批量导入数据功能
- python Django批量导入数据
- BootStrap扔进Django里的方法详解
- 在Python的Django框架中加载模版的方法
- 在Django中使用Sitemap的方法讲解
- 详解Django中的form库的使用
- Django中的CACHE_BACKEND参数和站点级Cache设置
- 剖析Django中模版标签的解析与参数传递
- Python中DJANGO简单测试实例
- Python的Django框架中的数据库配置指南
- 在Django的上下文中设置变量的方法
- 在Python的Django框架中编写编译函数
- 以一个投票程序的实例来讲解Python的Django框架使用
- 在Django的URLconf中进行函数导入的方法
- 在Python的Django框架中生成CSV文件的方法