gpt4 book ai didi

python - 如何将html直接传递给模板

转载 作者:行者123 更新时间:2023-11-30 22:42:44 24 4
gpt4 key购买 nike

我想直接将 HTML 作为 template() 中的参数传递。我知道我可以做这样的事情:

%for i in array:
<a>{{i}}</a>
%end

但我需要在调用模板时直接传递它,我尝试替换 &lt&gt< >使用javascript,但这不起作用。我想这样做:

{{results_of_i_in_array}}

并且循环将发生在我的主程序中而不是模板中,我从未发现有人问过同样的问题。注意:这个问题不是 this question 的重复问题.

我正在使用 Bottle 默认模板系统,提前致谢。

最佳答案

Bottle 文档:

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>!'

关于python - 如何将html直接传递给模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42021763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com