如何将HTML直接传递到模板 [英] How to pass html directly to template
问题描述
我想直接将HTML作为 template()
中的参数传递。
我知道我可以做类似的事情:
I want to pass HTML directly as a parameter in template()
.
I know I could do something like:
%for i in array:
<a>{{i}}</a>
%end
但是我在调用模板$ b $时需要直接传递它b我尝试将& lt
和& gt
替换为< >
使用javascript,但无法正常工作。
我要执行此操作:
but I need to pass it directly when I call template,
I tried replacing <
and >
with < >
with javascript but that did not work.
I want to do this:
{{results_of_i_in_array}}
,循环将在我的主目录而不是模板中发生,
我从未发现有人问过同样的问题。
注意:此问题不是此问题的重复。
and the loop will occur in my main rather than in the template, I never found anyone asking the same question. Note: this question is NOT a duplicate of this question.
我使用的是瓶装默认模板系统,谢谢。
I am using bottle default templating system, thanks in advance.
推荐答案
Bottle doc:
Bottle doc:
您可以使用感叹号开始表达式,以禁止
对该表达式转义
:
You can start the expression with an exclamation mark to disable escaping for that expression:
>>> template('Hello {{name}}!', name='<b>World</b>')
u'Hello <b>World</b>!'
>>> template('Hello {{!name}}!', name='<b>World</b>')
u'Hello <b>World</b>!'
这篇关于如何将HTML直接传递到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!