如何将pystache与web.py集成
现在,我在 web.py 中这样使用 pystache:
render = render_pystache('templates_dir')
class index:
def GET(self):
render.var('name', 'jim')
return render.simple()
simple.mustache
hello, {{name}}!
我为 web.py 写了一个渲染器
render_pystache.py
class render_pystache:
context = {}
def __init__(self, path):
self.path = path
def __getattr__(self, name):
from pystache import View
if self.context:
t = View(context = self.context)
else:
t = View(context = {})
t.template_path = self.path
t.template_name = name
return t.render
def var(self, key, value):
self.context[key] = value
有没有更好的方法将 pystache 和 web.py 结合起来?比如,如何实现下面这个功能?
render.simple({'name' : 'jim'})
1 个回答
2
我做了一个把pystache和web.py结合在一起的例子。你可以在这里看看:https://github.com/mattupstate/mustache-with-webpy