我正在使用twisted.web.template 制作一个网站,其中多个页面具有具有相同html 代码的子窗口。所以我想使用模板,只需将一个完整的 html 字符串转储到占位符中,只要有相同的代码。但是扭曲的模板系统引用了这些字符串(部分原因似乎是出于安全原因),因此浏览器无法将其解释为 html。有没有办法解决这个问题?这似乎是一个非常正常的使用场景,根据我的经验,它是 php 和 apache 的基本用途之一......
一些示例代码。我的模板看起来像这样
<html xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">
<body>
<div t:render="content" />
</body>
</html>
和我在 python 中的渲染类
class ExampleElement(Element):
loader = XMLFile(FilePath('template.xml'))
@renderer
def content(self, request, tag):
return tag('<b>This content should be in bold, but is quoted</b>')
我知道我可以写的最后一行(通过适当的导入)
return tag(tags.b('Bold content'))
但是我实际上想要放入的 html 字符串要大得多,而且这样写很不方便,而不仅仅是一个原始的 html 字符串