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


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


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



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


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

Compiling and collecting

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

$ 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


Next topic


This Page