现在,我以这种方式在 web.py 中使用 pystache:
render = render_pystache('templates_dir')
class index:
def GET(self):
render.var('name', 'jim')
return render.simple()
简单的小胡子
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'})