[英]XML format error nunjucks template rendering
I'm getting the following console error when rendering nunjucks templte that extends another: 渲染扩展另一个的nunjucks templte时,出现以下控制台错误:
Erro no processamento de XML: formatação incorreta Posição: http://localhost/prj/js/templates/template.tpl?s=1517784777473 Número da linha 1, coluna 1:
this roughly translates to: 这大致翻译为:
XML processing error: incorrect formatting Position: http://localhost/prj/js/templates/template.tpl?s=1517784777473 Line number 1, column 1:
(I couldn't find the error directly in it's english original form, that's why I translated it) (我无法直接以英语原始格式找到错误,这就是为什么我翻译了该错误)
Yet the template is rendered correctly. 模板仍然正确呈现。
The template that I'm rendering is this: 我正在渲染的模板是这样的:
{% extends "base/header.tpl" %}
{% block main %}
<div id="container">
<h1>Prj</h1>
<div id='element'>
whatever
</div>
</div>
{% endblock %}
this is header.tpl: 这是header.tpl:
<div>
<div id="header"></div>
{% block main %}{% endblock %}
</div>
this is nunjucks configuration: 这是nunjucks配置:
nunjucks.configure('js/templates', { autoescape: true, trimBlocks: true, lstripBlocks: true });
and this is how the rendering is done: 这是渲染的完成方式:
var renderization = nunjucks.render("main.tpl", {});
$("#root").append(renderization);
Anyone knows why I get this error ? 有人知道为什么我会收到此错误吗?
I think that this error is generated by the browser. 我认为此错误是由浏览器生成的。 When the nunjucks requests a next template from the server, the response comes marked as XML.
当nunjucks从服务器请求下一个模板时,响应标记为XML。 Browser try process it and throw error (because is a not XML).
浏览器尝试处理它并引发错误(因为它不是XML)。 You can simple check it: open browser console (F12) and go to network tab.
您可以简单地检查它:打开浏览器控制台(F12)并转到“网络”选项卡。
You must set mime-type as text/html
for nunjucks templates on http-server side. 对于http服务器端的nunjucks模板,必须将mime-type设置为
text/html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.