我阅读了Makotemplate的手册,并查看了以下代码:
from mako.template import Template
from mako.runtime import Context
from StringIO import StringIO
mytemplate = Template("hello, ${name}!")
buf = StringIO()
ctx = Context(buf, name="jack")
mytemplate.render_context(ctx)
print buf.getvalue()使用上下文有什么好处?
发布于 2011-07-28 20:00:18
您可能不会直接使用它,它同时包含输出缓冲区和可从模板中引用的变量字典。通常,使用Template的render方法更可取。
>>> Template('hello ${name}!').render(name='jack')
<<< u'hello jack!'你可以阅读更多关于它的here。
https://stackoverflow.com/questions/6858436
复制相似问题