Getting TemplateSyntaxError: unexpected char u'#' on including a Mustache template in html file served by python Google App Engine

左心房为你撑大大i 提交于 2019-12-10 13:17:14

问题


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:


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 %}.



来源:https://stackoverflow.com/questions/20932888/getting-templatesyntaxerror-unexpected-char-u-on-including-a-mustache-templa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!