python - 使用 pystache 渲染多个文件

标签 python pyramid

如何在 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/

相关文章:

python - 在 Bokeh 服务应用程序中绘制本地镜像

python - Django 中的空白搜索不会返回错误

python - 在哪里放置 ColanderAlchemy+Pyramid 的自动 setup_schema

python - 如何使用 Pyramid 检查浏览器 cookies 支持

python - 如何在 Pyramid 项目中添加自定义包?

python - 如何在 Python 中正确编写原始多行字符串?

python - 从 RGB 颜色列表创建调色板图像

python - Django:在项目目录中添加 random.py 文件破坏了 WSGI 中设置的导入

python - Pyramid - 是否可以在我的可调用 View 中将我的 mako 模板呈现为字符串?

javascript - 模板语言和 ajax 小部件