• Django 的css和js压缩插件:django_compressor


    今天尝试了django_conpressor,一个在django框架中压缩css和js的插件,灰常有用

    我把它加载在我的base的HTML template中,原来未经压缩的css和js是:

    1. <link rel="stylesheet" href = "include/style.css" type="text/css">      
    2. <link rel="stylesheet" href = "include/demo_page.css" type="text/css">  
    3. <link rel="stylesheet" href = "include/demo_table.css" type="text/css">  
    4.   
    5.   
    6. <script type="text/javascript" src="include/CloudTesting.js"></script>  
    7. <script src='include/jquery.min.js' type='text/javascript'></script>   
    8. <script type='text/javascript' src='include/jquery.dataTables.js'></script>  


    压缩后会变成:

    1. <link rel="stylesheet" href="include/CACHE/css/31b7bf7183d6.css" type="text/css" />  
    2. <script type="text/javascript" src="include/CACHE/js/3b54f0a1ee64.js"></script>  


    具体的做法:

    详细的参见官方说明:http://django_compressor.readthedocs.org/en/latest/quickstart/

    自己整理的关键步骤:

    1. 安装:

    pip install django_compressor

    2. 添加到setting.py中:

    INSTALLED_APPS = (
        # other apps
        "compressor",
    )
    STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.FileSystemFinder',
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
        # other finders..
        'compressor.finders.CompressorFinder',
    )

    3. 在settings.朋友中加入一些必要的配置:

    COMPRESS_ROOT = 'Templates/include/'
    COMPRESS_URL = 'include/'
    COMPRESS_ENABLED = True

    4. 使用起来很方便:

    [html] view plaincopy
     
    1. {% load compress %}  
    2. {% compress css %}  
    3. <link rel="stylesheet" href = "include/style.css" type="text/css">      
    4. <link rel="stylesheet" href = "include/demo_page.css" type="text/css">  
    5. <link rel="stylesheet" href = "include/demo_table.css" type="text/css">  
    6. {% endcompress %}  
    7. {% compress js %}  
    8. <script type="text/javascript" src="include/CloudTesting.js"></script>  
    9. <script src='include/jquery.min.js' type='text/javascript'></script>   
    10. <script type='text/javascript' src='include/jquery.dataTables.js'></script>  
    11. {% endcompress %}  


    一切搞定了,运行起来就是压缩后的效果了

    注意:

    COMPRESS_URL一定要以“/”结尾,否则会报“django.core.exceptions.ImproperlyConfigured: URL settings (e.g. COMPRESS_URL) mu
    st have a trailing slash”这样的错

    转自: http://blog.csdn.net/quicktest/article/details/7995715?utm_source=tuicool

  • 相关阅读:
    中标麒麟QT5编译出现:cannot find -lGL 和 collect2:error:ld returned 1 exit status 错误
    虚拟机设置静态ip【实测中标麒麟】
    selenium webdriver如何拿到页面的加载时间
    有感于去哪儿的一道笔试题
    python selenium 常见问题列表
    乙醇的webdriver实用指南java版本
    乙醇的webdriver实用指南ruby版本
    作死的自动化测试
    从龙门镖局看自动化测试
    无用的自动化测试
  • 原文地址:https://www.cnblogs.com/pinganzi/p/4814637.html
Copyright © 2020-2023  润新知