Package: django-css
Django-css is a fork ofdjango_compressorthat makes it easy to use CSS compilers with your Django projects. CSS compilers extend CSS syntax to include more powerful features such as variables and nested blocks, and pretty muchrockall around. Django-css can currently be used with any CSS compiler that can be called from the command line, such asHSS,Sass,CleverCSS, orLESS.Thanks to django_compressor, django-css will also version and compress linked and inline javascript or CSS into a single cached file. These cached files will get served through whatever frontend server you use for serving static files, because serving static files through Django is just silly.Note: The pypi version of CleverCSS is buggy and will not work with django-css. Use the updated version on github:http://github.com/dziegler/clevercss/tree/masterInstallationAddcompressorto INSTALLED_APPS. You should also enable some type of caching backend such as memcached, e.g.CACHE_BACKEND ='memcached://127.0.0.1:11211/'. Don’t worry, your static files are not being served through Django. The only thing stored in cache is the path to the static file.NEW in v2.2!Django-css now uses Django’s storage backend when saving compressed files. This means that if you’re using something like the S3 backend indjango-storages, your compressed files will automatically be saved to S3. If not, everything should function as normal. Check outdjango-storagesfor more info on custom storage backends.UsageSyntax:{% load compress %}
{% compress <js/css> %}
<html of inline or linked JS/CSS>
{% endcompress %}Examples:{% 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 %}Which would be rendered like:<link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8">or:{% 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 %}Which would be rendered like:<script type="text/javascript" src="/media/CACHE/js/3f33b9146e12.js" charset="utf-8"></script>If you’re using xhtml, you should use:{% load compress %}
{% compress css xhtml %}
<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" />
{% compress css %}Which would be rendered like:<link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8" />SettingsCOMPILER_FORMATSdefault: {}A dictionary specifying the compiler and arguments to associate with each extension.django-css will select which CSS compiler to use based off a file’s extension. For example:COMPILER_FORMATS = {
    '.sass': {
        'binary_path':'sass',
        'arguments': '*.sass *.css'
    },
    '.hss': {
        'binary_path':'/home/dziegler/hss',
        'arguments':'*.hss'
    },
    '.ccss': {
        'binary_path':'clevercss',
        'arguments': '*.ccss'
    },
}will use Sass to compile*.sassfiles, HSS to compile*.hssfiles, and clevercss to compile*.ccssfiles.*.cssfiles will be treated like normal css files.binary_path is the path to the CSS compiler. In the above example, sass and clevercss are installed in my path, and   hss is located at /home/dziegler/hss.arguments are arguments you would call in the command line to the compiler. The order and format of these will depend on the CSS compiler you use. Prior to compilation, * will be replaced with the name of your file to be compiled.If this seems a little hacky, it’s because I wanted to make it easy to use whatever CSS compiler you want with as little setup as possible.COMPRESSdefault: the opposite ofDEBUGBoolean that decides if compression will happen.COMPRESS_CSS_FILTERSdefault: []A list of filters that will be applied to CSS.COMPRESS_JS_FILTERSdefault: [‘compressor.filters.jsmin.JSMinFilter’])A list of filters that will be applied to javascript.COMPRESS_URLdefault:MEDIA_URLControls the URL that linked media will be read from and compressed media
will be written to.COMPRESS_ROOTdefault:MEDIA_ROOTControls the absolute file path that linked media will be read from and
compressed media will be written to.COMPRESS_OUTPUT_DIRdefault:“CACHE”Controls the directory insideCOMPRESS_ROOTthat compressed files will
be written to.ABSOLUTE_CSS_URLSdefault:TrueIf True, all relative url() bits specified in linked CSS files are automatically
converted to absolute URLs while being processed. Any local absolute urls (those
starting with a ‘/’) are left alone.NotesStylesheets that are @import’d are not compressed into the main file. They are
left alone.If the media attribute is set on <style> and <link> elements, a separate compressed file is created and linked for each media value you specified. This allows the media attribute to remain on the generated link element, instead of wrapping your CSS with @media blocks (which can break your own @media queries or @font-face declarations). It also allows browsers to avoid downloading CSS for irrelevant media types.Linked files must be on your COMPRESS_URL (which defaults to MEDIA_URL).
If DEBUG is true off-site files will throw exceptions. If DEBUG is false
they will be silently stripped.CSS files are compiled only when needed, because it would be silly to re-compile on every page request. The way this works is that django-css looks at the time your css was last modified, and the time your CleverCSS, HSS, etc file was modified. If the modification time for the CleverCSS, HSS, etc file is after the css file’s, then the css file gets re-compiled.If COMPRESS is False (defaults to the opposite of DEBUG) CSS files will still be compiled if needed, but files will not be compressed and versioned.The pypi version of CleverCSS is buggy and will not work with django-css. Use the updated version on github:http://github.com/dziegler/clevercss/tree/masterRecommendations:Use only relative or full domain absolute urls in your CSS files.Avoid @import! Simply list all your CSS files in the HTML, they’ll be combined anyway.Changes from 1.0.0, aka the version from google codeDjango-css was previously usingdjango-compressfor versioning and compression, and it now usesdjango_compressor. The main reasons being that with django_compressor, css/js files are included in the template itself, not in settings, and versioning is much cleaner. Version 2 requires much less setup and is easier to use, but is not compatible with version 1.Special thanks to Christian Metts and Andreas Pelme for all their hard work on django_compressor and django-compress.DependeciesBeautifulSoup