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:
First, set up django-compressor.
# Install django-compressor
$ pip install django_compressor
Include the following in your settings.py
.
# settings.py INSTALLED_APPS = [ # Other apps... 'compressor', ] STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # other finders.. 'compressor.finders.CompressorFinder', ) COMPRESS_PRECOMPILERS = ( ('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/cupofjoe.coffee" type="text/coffeescript"></script> {% endcompress %}