How to pass html directly to template

最后都变了- 提交于 2019-12-14 04:20:00

问题


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

but I need to pass it directly when I call template, I tried replacing &lt and &gt 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.


回答1:


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 &lt;b&gt;World&lt;/b&gt;!'
>>> template('Hello {{!name}}!', name='<b>World</b>')
u'Hello <b>World</b>!'


来源:https://stackoverflow.com/questions/42021763/how-to-pass-html-directly-to-template

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