I have my development server ( django 1.5 ). In this server i can create javascript templates without problem.
The empty view just returns a template. Now, in this template i have the following code:
{% load verbatim %}
<!DOCTYPE html>
<html>
<head>
<link href="http://0.0.0.0:8080/css/bootstrap/2.3.1/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://0.0.0.0:8080/css/bootstrap/2.3.1/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="result"></div>
</div>
</div>
</div>
<!-- The javascript template -->
<script src="http://blueimp.github.io/JavaScript-Templates/js/tmpl.min.js"></script>
{% verbatim %}
<script type="text/x-tmpl" id="tmpl-demo" src="">
<h3>{%=o.title%}</h3>
<p>Released under the
<a href="{%=o.license.url%}">{%=o.license.name%}</a>.</p>
<h4>Features</h4>
<ul>
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% } %}
</ul>
</script>
{% endverbatim %}
<!-- The javascript -->
<script type="text/javascript">
var data = {
"title": "JavaScript Templates",
"license": {
"name": "MIT license",
"url": "http://www.opensource.org/licenses/MIT"
},
"features": [
"lightweight & fast",
"powerful",
"zero dependencies"
]
};
document.getElementById("result").innerHTML = tmpl("tmpl-demo", data);
</script>
</body>
</html>
For the record: The tag {% verbatim %} is used so django template engine ignores the template script as they both use a very similar syntax
Now, when i try running the same same page in the main server, which is using apache and django 1.4.5, the template script seems not to be recognized. In firebug i get the following error:
SyntaxError: unexpected garbage after function body, starting with '}'
If i remove all the javascript template tags inside the text/x-tmpl script, then no error is displayed.
This leads me to think that the browser thinks that the text/x-tmpl is javascript because:
- I am missing to send something in the view
- Something missing in my apache configuration
I tried to search around, but i couldnt find anything.
Does any of you have idea how to fix this?
Thanks :)
Edit 1: This is the link to the javascript templates wiki https://github.com/blueimp/JavaScript-Templates
Edit 2: This is the django view
@login_required
def test(request):
return render_to_response('myapp/test.html', locals(), context_instance = RequestContext(request))
{% load verbatim %}?verbatim, there is no need of{% load verbatim %}