/django-assetfiles

Drop-in replacement for staticfiles with asset processing.

Primary LanguagePythonMIT LicenseMIT

Django Assetfiles

Django Assetfiles is a drop-in replacement for staticfiles which handles asset processing.

Installation

  1. Install package from PyPi:

    $ pip install django-assetfiles
  2. Replace 'django.contrib.staticfiles' in INSTALLED_APPS with 'assetfiles':

    INSTALLED_APPS = (
        # ...
        # 'django.contrib.staticfiles',
        'assetfiles',
    )
  3. That's it! Assetfiles will default to your Staticfiles settings.

Usage

  1. Add an asset file that should be processed:

    // static/css/main.scss
    $color: red;
    
    body {
      color: $color;
    }
  2. Add a link to the processed CSS file in your template (you can use standard Staticfiles conventions):

    {% load staticfiles %}
    <link href="{% static 'css/main.css' %}" rel="stylesheet">

    Assetfiles will automatically serve up the processed version of main.scss at the static url of /static/css/main.css.

  3. To serve assets in development, either use runserver as normal or add the following to your urls.py:

    from assetfiles.urls import assetfiles_urlpatterns
    
    # ... the rest of your URLconf goes here ...
    
    urlpatterns += assetfiles_urlpatterns()
  4. For deployment, run collectstatic as usual and Assetfiles will process and copy over the assets:

    $ python manage.py collectstatic
    $ cat public/css/main.css
    body {
      color: red; }

Copyright

Copyright (c) 2012 LocalMed, Inc.. See LICENSE for details.