开发者

how to integrate pystache with web.py

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'})


I built an example of integrating pystache with web.py. Have a look here: https://github.com/mattupstate/mustache-with-webpy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜