如何在 pystache 中使用部分布局?我还没有找到任何这样做的文档。我正在寻找类似的东西
布局.html
<html>
<body>
{{<body}}
</body>
</html>
索引.html
<section>
{{name}}
</section>
编辑:
我已经使用 node.js 完成了这项工作,并且熟悉模板语法,但我不确定如何告诉 pystache 加载这两个文件。
Pystache 只是 Mustache 的 Python 实现,因此 Mustache 文档也应该适用于 Pystache。查看手册页的Partials 部分。
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 源代码。