All I want to do is. . .

. . .use Coffeescript in a Django app.


Description: Using Coffeescript in Django is much simpler than you might think.
Contributors: sloria
Updated: 07/14/13

Do these first:

  • Install Coffeescript
    # Mac-specific instructions
    # Install node
    $ brew update 
    $ brew install node
    # In you shell profile (.bash_profile, .zshrc, etc.), add this line
    export PATH=/usr/local/share/npm/bin:$PATH
    # Install coffee (notice the dash)
    npm install -g coffee-script
    # To compile a file
    coffee -c
    # Watch mode--compile a file whenever it is changed
    coffee -cw
     [full instructions]

First, set up django-compressor.

# Install django-compressor
$ pip install django_compressor

Include the following in your


    # Other apps...

    # other finders..

    ('text/coffeescript', 'coffee --compile --stdio'),

That's it! You can now include .coffee files in your html. Make sure to include them between {% compress js %} tags and set the type attribute for the script tag to text/coffeescript.

# some_template.html

{% compress js %}
<script src="{{ STATIC_URL }}coffee/" type="text/coffeescript"></script> 
{% endcompress %}


If you have suggestions, corrections, or content to contribute, fork us at our Github repo or open an issue.

Licensed under the CC-SA.