gpt4 book ai didi

python - Pystache 无需转义(未转义)

转载 作者:太空狗 更新时间:2023-10-29 22:29:37 30 4
gpt4 key购买 nike

我正在使用 pystache 来呈现模板。当我呈现具有 & 的上下文变量时,我在输出中得到了 &。如何摆脱 & 我需要 & 的地方。Django 模板也发生了同样的事情

>>> pystache.render('The URL {{URL}}', {'URL': 'http://google.com?a=3&b=3'})
u'The URL http://google.com?a=3&b=3'

最佳答案

要防止转义,请使用三重大括号 {{{var}}}

为防止转义,请使用三重大括号 {{{URL}}} 而不是双大括号 {{URL}}

>>> pystache.render('The URL {{{URL}}}', {'URL': 'http://google.com?a=3&b=3'})
u'The URL http://google.com?a=3&b=3'

我已经在今天的最新版本 0.5.4

上对此进行了测试

mustache 文档

由于 Pystache 是 Python 中的 Mustache 实现,您可以使用 Mustache 的文档作为指针。

All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.

来源:https://mustache.github.io/mustache.5.html

关于python - Pystache 无需转义(未转义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34829472/

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