如何在 pystache 中使用部分布局?我无法找到任何执行此操作的文档。我正在寻找类似的东西
布局.html
<html>
<body>
{{<body}}
</body>
</html>
index.html
<section>
{{name}}
</section>
编辑:
我已经使用 node.js 完成了此操作,并且熟悉模板语法,但我不确定如何告诉 pystache 加载这两个文件。
最佳答案
Pystache 只是 Mustache 的 Python 实现,因此 Mustache 文档也应该适用于 Pystache。查看Partials section手册页的内容。
layout.mustache
<html>
<body>
{{> body}}
</body>
</html>
body.mustache
<section>
{{name}}
</section>
<小时/>
下面是在 Pystache 中渲染上述模板的示例(与 .mustache
文件位于同一目录):
>>> import pystache
>>> renderer = pystache.Renderer()
>>> renderer.render_path('layout.mustache', {'name': 'test'})
u'<html>\r\n <body>\r\n <section>\r\n test\r\n ...'
有关更多信息,请查看Pystache source .
关于python - 使用 pystache 渲染多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13918028/