Python-compress Django css / js

django-css

It compresses css / js. The cache is generated when the page is accessed. If DEBUG = True is specified in settings.py, it will not be compressed.

1 Install with pip

python


    $ pip install django-css

2 Edit settings.py

python


    # MEDIA_ROOT、MEDIA_Make sure the URL is set up properly
    MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'www')
    MEDIA_URL = '/www/'

    INSTALLED_APPS = (
        # 'compressor'Add
        'compressor',
    )
  1. How to use in template

python


    {% load compress %}
    {% compress css %}
    <link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">
    <link rel="stylesheet" href="/media/css/two.sass" type="text/css" charset="utf-8">
    {% endcompress %}

    {% load compress %}
    {% compress js %}
    <script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">obj.value = "value";</script>
    {% endcompress %}
  1. Make sure that the source code is compressed when accessing the page

python


    <link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8">
    <script type="text/javascript" src="/media/CACHE/js/3f33b9146e12.js" charset="utf-8"></script>

Package Index django-css 2.3.1

Recommended Posts

Python-compress Django css / js
Python Django CSS reflected
[Django] About static file related settings (css, js)
Django
How to reflect CSS in Django
CSS environment created in 10 minutes using Django
Edit Django shift table HTML and CSS
Resolve Angural JS and Django template conflicts