Python Mako Template 简要介绍
Mako是什么?Moko是Python写的一个模板库,Python官网http://python.org/ 用的就是它哦。
(Mako官网地址:http://www.makotemplates.org/ ,可以下载安装包,推荐使用 easy_install
安装, 或者 通过 pip
)
先来个简单的使用示例, 通过文本直接构建模板
from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()
mytemplate = Template("hello, ${name}!")
print mytemplate.render(name="jack")
通过文件构建模板
mytemplate = Template(filename='/docs/example.txt')
print mytemplate.render()