How to pass html directly to template

2019-08-04 02:20发布

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条回答
Ridiculous、
2楼-- · 2019-08-04 02:58

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>!'
查看更多
登录 后发表回答