Django and Mustache use the same syntax for template

DB Tsai picture DB Tsai · Nov 2, 2011 · Viewed 8.9k times · Source

I try to smuggle HTML template in the HTML for mustache.js, however the django template engine remove all the placeholders that should be output as-is to the front-end

The template is included in HTML in this way:

<script type="text/x-mustache-template" data-id="header_user_info">
    <div id="header_user_info">
        <div id="notification">0</div>
        <a href="#">{{username}}</a>
    </div>
</script>

and I can get the HTML template by running $(el).html(), and generate html by using Mustache.to_html(temp, data);

I could put all the template into another static file and serve from CDN, but then it would be hard to track where the template belongs, and at least one extra http request.

Answer

surjikal picture surjikal · Jun 11, 2012

You can simply change the tags:

Mustache.tags = ['[[', ']]'];