Rendering Multiple Files with pystache

风格不统一 提交于 2020-02-25 08:42:26

问题


How do you use partial layouts in pystache? I haven't been able to find any documentation for doing this. I'm looking for something along the lines of

layout.html

<html>
   <body>
     {{<body}}
  </body>
</html>

index.html

<section>
    {{name}}
</section>

Edit:

I've done this using node.js and am familiar with the templating syntax, but I'm not sure how to tell pystache to load both files.


回答1:


Pystache is just a Python implementation of Mustache, so the Mustache documentation should apply to Pystache as well. Check out the Partials section of the man page.

layout.mustache

<html>
   <body>
     {{> body}}
  </body>
</html>

body.mustache

<section>
    {{name}}
</section>

Here's an example of rendering the above templates in Pystache (from the same directory as the .mustache files):

>>> 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     ...'

For more info, check out the Pystache source.



来源:https://stackoverflow.com/questions/13918028/rendering-multiple-files-with-pystache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!