Working with Django and client side frameworks using similar tags

If you’re developping in Django and want to use some client-side frameworks like Backbone.js or Angular.js, may be you are wondering how to mix both of these client and server side frameworks especially if they are using very similar tags as {{ tag }}.

The solution came with django 1.5 and its brand new verbatim tag. If you want to insert client-side framework tags inside your django templates, just surround your code like this :

{% verbatim %} Your jQuery.js/Backbone.js/Angular.js/SomethingElse.js code {% endverbatim %}

Et voilà !

If you’re using a previous version of django you can plug this django file in your project and do the exact same manipulation.

As said by Janos in the comment section, you can change the delimiters of the client-side framework if this one provide a way to do so. For example, in AngularJS you could try

myModule.config(function($interpolateProvider) {

more details here and here

One thought on “Working with Django and client side frameworks using similar tags

  1. I think in general it is more practical to change the markup in one of the tools. In AngularJS you can do this using the `$interpolateProvider`. For example you could replace `{{` with “ and voila 😉

Leave a Reply