Package: django-handlebars
django-handlebars integratesHandlebarsJavaScript templating engine withDjango. It provides Python and JavaScript helpers for wrapping templates inclusion and loading routines. Optionaly django-handlebars providesmanage.pycommands facilitating compilation (requirespython-spidermonkey) and live templates assets synchronization as you developing (requirespyinotify).How to installInstall package from PyPipip installdjango-handlebars. Or alternatively pull the repo and runpython setup.py installAdddjango_handlebarsto project’ssettings.INSTALLED_APPSOptionaly addHANDLEBARS_*configuration parameters to thesettings.py. Seedjango_handlebars.appsettingsfor available options and explanationsRun./manage.py test django_handlebarsto check configuration and requirments.That should be it. Application is not providing any models or URLs.How to usedjango-handlebars can work in two modes: compiling templates in browser and rendering templates pre-compiled on server side. In both scenarios templates might be loaded dynamically with AJAX request or included on page to prevent extra HTTP requests.First you have to drop in Handlebars scripts on page:{% load handlebars_tags %}
<html>
<head>
  {% handlebars_scripts %}
</head>
<body></body>
</html>Which will addhandlebars_configvariable storing configuration,scripttags forhandlebars.js(orhandlebars.runtime.jsifsettings.HANDLEBARS_COMPILEDisTrue) and handlebars.django.js. Django-handlebars provides template loading client (see handlebars.django.js) by extending Handlebars object with tpl() method.Compiling in browserThis mode is simpler and doesn’t require optional dependencies to be satisfied. But it adds a little overhead. In this case Handlebars will parse  template every other page load and parser script has to be loaded in addition to renderer.Assuming you have configured application and your Handlebars*.htmltemplates are accessiable from static URL, your typical usage pattern will look like this:var data = {title: "The title", body: "whatever"}

Handlebars.tpl("your/template/spec", {
    success: function(renderer){
        console.log("Rendered template:", renderer(data));
    },
    error: function(xhr, err){
        console.warn("Ooops, can't load template", err);
    }
});Notice that template path doesn’t include dir URL and extension. Starting slash is tolerated.Handlebars.tplis NOT returning template, havingsuccesscallback is the only way to get it.By default client attempts to usejQueryif it’s available, otherwise it will fall back to it’s own simple crossbrowser XHR implementation. In case jQuery is availableHandlebars.tpl()call would return jQuery.Deferred object, so chaining and other benefits may be used:var df = Handlebars.tpl("your/template/spec");

df.done(function(renderer){
    console.log("Rendered template:", renderer(data));
}).fail(function(xhr, err){
    console.warn("Ooops, can't load template", err);
});Loader appends .html extension and pulls file fromsettings.HANDLEBARS_TPL_URLUsing pre-compiled templatesIn this mode your JavaScript code stays same, but client will attempt to pull .js file fromsettings.HANDLEBARS_TPL_URL. Pre-compiled file contains JS function generated byHandlebars.precompile(str_template). You can run this command right in a browser console to see how it looks. Django-handlebars provides manage.py commands to build those files in a batch.Eliminating extra requestsIn both cases described above HTTP request will be made, which lowers performance. To avoid that include you templates on page::{% handlebars_template "your/template/spec" %}This will cache template by callingHandlebars.tpl("your/template/spec",tpl). Described technique works for both regular and pre-compiled modes.How to compileRun./manage.py compilehandlebars--help:--clean               Remove all previously compiled templates
--watch               Watch for changes within appsettings.TPL_DIR and compile
--raw                 Do not format output
--quiet               Run with no outputDjango-hadlebars compiles templates by running Handlebars script usingSpiderMonkeyand requirespython-spidermonkeypackage to be installed.So far--watchoption is available on Linux platform only since it’s usingpyinotify. Support for other platforms might be added in future.If either of these two is not installedcompilehandlebarswill exit with appropriate error message.Oncompilehandlebarsstart all template files with mtime newer than compiled file mtime will be re-compiled. If you run command without--watchcompiler exits once all files compiled, otherwise it will hang until you pressCtl-C.LicenseCopyright 2012 Sergii Iavorskyi, Licensed new-style BSD. ContainsHandlebars.jscopyright 2011 Yehuda Katz. See LICENSE file for more information.