如何将 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'})
Now, I use pystache in web.py in this way:
render = render_pystache('templates_dir')
class index:
def GET(self):
render.var('name', 'jim')
return render.simple()
simple.mustache
hello, {{name}}!
I wrote a render for 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
Is there any better way to integrate pystache with web.py? for example, how to implement the following function?
render.simple({'name' : 'jim'})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我构建了一个将 pystache 与 web.py 集成的示例。看看这里:https://github.com/mattupstate/mustache-with-webpy
I built an example of integrating pystache with web.py. Have a look here: https://github.com/mattupstate/mustache-with-webpy