简体   繁体   中英

XML format error nunjucks template rendering

I'm getting the following console error when rendering nunjucks templte that extends another:

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:

<div>
    <div id="header"></div>
    {% block main %}{% endblock %}
</div>

this is nunjucks configuration:

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. Browser try process it and throw error (because is a not XML). You can simple check it: open browser console (F12) and go to network tab.

You must set mime-type as text/html for nunjucks templates on http-server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM