I am getting a TemplateSyntaxError: unexpected char u'#' error, when I include a simple Mustache template in my HTML file being served by Python Google App Engine server.

The mustache template that I want to include is:

{{#item}} {{name}} {{/item}}

My HTML file looks like this:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/mustache-template" id="myTemplate">
      {{#item}}{{name}}{{/item}}
    </script>
  </head>
</html>

Since, the template is wrapped around a script tag with type=text/mustache-template, shouldn't the server just ignore it?

I am unable to comprehend, why am I getting the TemplateSyntaxError and what should I do to get rid of it. Anyone has any ideas? Thanks!

1

There are 1 answers

2
Daniel Roseman On BEST ANSWER

You don't say so, but I guess you are using either Django or Jinja2 templates on the server side. In which case, no they wouldn't ignore content inside a mustache script tag: for one thing, they know nothing about mustache, and secondly it's fairly common practice to actually put server-side template tags inside Javascript, for instance to provide initial values for functions.

In Django versions greater than 1.5, you can wrap your mustache tags with the {% verbatim %}...{% endverbatim %} tag to prevent server-side evaluation. Jinja2's equivalent is {% raw %}...{% endraw %}.