Python 如何将pystache与web.py集成
现在,我在web.py中使用pystache的方式如下:Python 如何将pystache与web.py集成,python,web.py,mustache,Python,Web.py,Mustache,现在,我在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:
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'})
我构建了一个将pystache与web.py集成的示例。请看这里: