Skip to content

Instantly share code, notes, and snippets.

@cloverrose
Created June 24, 2013 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloverrose/5849478 to your computer and use it in GitHub Desktop.
Save cloverrose/5849478 to your computer and use it in GitHub Desktop.
Django 1.5 introduced {% verbatim %} template tag. It stops template from parsing contents of this tag.
<html>
<head>
</head>
<body>
Welcome {{ name }}!!
<div id="container"></div>
{% verbatim %}
<script type="text/x-handlebars-template" id="mytemplate">
<h2>{{ message }}</h2>
</script>
{% endverbatim %}
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="https://raw.github.com/wycats/handlebars.js/1.0.0/dist/handlebars.js"></script>
<script>
var source = $("#mytemplate").html();
var template = Handlebars.compile(source);
var content = {
message: "Django with Handlebars!! So Cool!!",
};
var html = template(content);
$('#container').append(html);
</script>
</body>
</html>
from django.shortcuts import render_to_response
def index(request):
return render_to_response('myapp/django_with_handlebars.html', {'name': 'rose'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment