Embed mustache-like Javascript templates into Django templates with minimal fuss.
Python JavaScript
Pull request Compare This branch is 107 commits ahead, 12 commits behind carljm:master.
Failed to load latest commit information.
docs Include migration instructions in the readme Sep 6, 2012
mustachejs Update the version to reflect the fact that this version is at end-of… Sep 6, 2012
.gitignore Additions to .gitignore Oct 19, 2011
.travis.yml Update tests to use Django 1.4 and trunk Apr 2, 2012
CHANGES.rst Update the version to reflect the fact that this version is at end-of… Sep 6, 2012
LICENSE.txt Update years in LICENSE.txt Aug 17, 2012
MANIFEST.in Add MANIFEST.in to the manfest file (itself). Hopefully this will let… Dec 27, 2011
README.rst Include migration instructions in the readme Sep 6, 2012
runtests.py Renamed the app from icanhaz to mustachejs; Dec 6, 2011
setup.py Update the stability designation to beta Aug 17, 2012
tox.ini Version 0.2.0. Jun 27, 2011


NOTE: django-mustachejs is now named "django-jstemplate"!

The source is available at http://github.com/mjumbewu/django-jstemplate, and the package is at http://pypi.python.org/pypi/django-jstemplate/. Please update your references.

Migration is easy:

  • In your settings' INSTALLED_APPS, mustachejs becomes jstemplate
  • MUSTACHEJS_... settings become JSTEMPLATE_...
  • In your Django templates, {% load mustachejs %} becomes {% load jstemplate %}

That's it. If you have any issues, get in touch with me on GitHub or on Twitter @mjumbewu. Thanks for using the project!


build status

A templatetag framework for easier integration of mustache.js JavaScript templates with Django templates. Inspired by ICanHaz.js, django-icanhaz, and jquery.mustache.

NOTE: Though django-mustachejs was originally developed for mustache-style templates, it can actually be used to embed any type of client-side templates. It might be better named django-jstemplates or something like that.

Quick Usage

(Read the full docs on Read the Docs)

Add "mustachejs" to your INSTALLED_APPS setting.


  <p>This is {{ name }}'s template</p>


{% load mustachejs %}

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
  <script src="{{ STATIC_URL }}mustache/js/mustache-0.3.0.js"></script>
  <script src="{{ STATIC_URL }}mustache/js/django.mustache.js"></script>

  <div id="dynamic-area"></div>

  {% mustachejs "main" %}

    $(document).ready(function() {

      var $area = $('#dynamic-area')
        , template;

      template = Mustache.template('main');


Rationale (from django-icanhaz)

The collision between Django templates' use of {{ and }} as template variable markers and mustache.js' use of same has spawned a variety of solutions. One solution simply replaces [[ and ]] with {{ and }} inside an mustachejs template tag; another makes a valiant attempt to reconstruct verbatim text within a chunk of a Django template after it has already been mangled by the Django template tokenizer.

I prefer to keep my JavaScript templates in separate files in a dedicated directory anyway, to avoid confusion between server-side and client-side templating. So my contribution to the array of solutions is essentially just an "include" tag that avoids parsing the included file as a Django template (and for convenience, automatically wraps it in the script tag that ICanHaz.js expects to find it in).