Nunjucks: how to render html tag what get from other server

Created on 15 May 2017  Â·  2Comments  Â·  Source: mozilla/nunjucks

i write a page ,the layout tmp is get from another server ,i render the data on the page ,it is just as a string on the page not as the html tags show it.
is there a fun to render the page on this question?

---------------------------more---------------------

example:
my server‘s ip is 10.101.100.1
I get a template string from interface http://10.101.100.3/template
The interface data returned is "\

this is the page title\

test\

\
"
I assign the data to a variable named str

index.js:
var data.header = str;
data.list={a:1,b:2,c:3};
var html = env.render('index.html',data);
ctx.response.body = html;

index.html:
{{ str }}
\

list\


{% for f in list %}
\

{{ f }}\


{% endfor %}

then,
In the browser, list is ok,but header tag in the str is as the string output in the page when i opend the page

browser show:

\

this is the page title\

test\

\

1
2
3

Most helpful comment

I have a gut sense that you're looking for the escape safe filter, but I could be incorrect.

EDIT: I still think you're looking for the safe filter. Try this:

{{ str | safe }}

All 2 comments

Can you be more specific? It's unclear what you're trying to do and what doesn't work. Thanks!

I have a gut sense that you're looking for the escape safe filter, but I could be incorrect.

EDIT: I still think you're looking for the safe filter. Try this:

{{ str | safe }}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kud picture kud  Â·  3Comments

wslx520 picture wslx520  Â·  4Comments

popomore picture popomore  Â·  6Comments

RomainLanz picture RomainLanz  Â·  4Comments

sandiprb picture sandiprb  Â·  5Comments