Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将pystache与web.py集成_Python_Web.py_Mustache - Fatal编程技术网

Python 如何将pystache与web.py集成

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:

现在,我在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'})

我构建了一个将pystache与web.py集成的示例。请看这里: