Pystache在使用多个文件时替换了html字符

2024-09-30 04:26:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pystache(在python3.4上)来模板HTML文件以通过电子邮件发送。 我有一个main.mustache文件,其中一些标记将被其他.mustache文件的内容替换。 所以我有这样的东西(简体版):

在大胡子:

<body>
<table>
.......
{{some_params}}
....
</table>

{{special_warning}}
</body>

{{special_warning}}标记仅在某些情况下使用,并且来自文件special_warning.mustache

^{pr2}$

在python脚本中,我会:

special_message = ''
if <some condition>:
    special_message = renderer.render_path('special_warning.mustache', {})

proc_templ = renderer.render_path('main.mustache', {'special_warning': special_message , <the other params>})

我得到的结果是main.mustache部分的正确消息,但是来自special_warning.mustache的部分是HTML编码的:

<body>
<table>
.......
some_params
....
</table>

&lt;table&gt;
  &lt;tbody&gt;
  ....
  &lt;/tbody&gt;
&lt;/table&gt;

</body>

有什么办法阻止这种html编码吗?是pythonstring在做这件事,还是pystache呈现来做呢?在


Tags: 文件标记ltgtmessagemainhtmltable
1条回答
网友
1楼 · 发布于 2024-09-30 04:26:27

使用三方括号可避免html转义。我的so大胡子应该是:

<body>
<table>
.......
{{some_params}}
....
</table>

{{{special_warning}}}
</body>

相关问题 更多 >

    热门问题