Как интегрировать фисташку с web.py

Теперь я использую pystache в web.py следующим образом:

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 ответ

Решение

Я построил пример интеграции фисташки с web.py. Посмотрите здесь: https://github.com/mattupstate/mustache-with-webpy

Другие вопросы по тегам