Configuration

In your project settings, override Django’s default static files storage with the staticassets storage to compile and collect your assets to be served in production, and define which manifests you want to compile

STATICFILES_STORAGE = 'staticassets.storage'

STATICASSETS_MANIFESTS = ('css/application', 'js/application')

Templates

In the templates file, load the staticassets and link your manifests (no need to specify the file extension), the path is appended to the STATIC_ROOT location

{% load staticassets %}

  {% stylesheet "css/application" %}
    <link rel="stylesheet" href="{{ asset.url }}"/>
  {% endstylesheet %}

  {% javascript "js/application" %}
    <script src="{{ asset.url }}"></script>
  {% endjavascript %}

Manifests files

staticassets uses the same directives syntax and preprocessing as Sprockets you can use Sass, Less and Stylus for stylesheets, and Coffeescript or EJS for scripts, Their compilers just have to be available on the path

Example

stylesheets:

/*
 *= require application/styles/fonts/lato
 *= require application/styles/fonts/awesome
*/

scripts:

//= require foundation/jquery
//= require foundation

Compiling and collecting

To compile and collect your assets to the STATIC_ROOT location, use the collectstatic command

$ manage.py collectstatic

Aditional compilers

If you need to develop an aditional compiler for css or javascript, just follow the same directives as the other compilers : extend them from the CommandCompiler and specify the command and the params, then add them to the COMPILERS dictionary on the static assets settings

Table Of Contents

Previous topic

Installation

Next topic

Changelog

This Page