一个非固执己见的模板抽象层
TemplateAlchem的Python项目详细描述
tl;dr
安装:
$ pip install templatealchemy使用:
importtemplatealchemyasta# create a top-level template managerroot=ta.Manager(source='pkg:mypackagename:lib/templates',renderer='mako',)# load the sub-template 'foo'foo=root.getTemplate('foo')# render the 'text' version with some parameters; the# actual template is then in 'mypackagename:lib/templates/foo.text'params=dict(value='bar',zig='zog')text=foo.render('text',params)# get meta information about the templateif'attachments'infoo.meta:forattachmentinfoo.meta.attachments:# ... do something with each attachment# supported formats are stored in meta.formatsassert(foo.meta.formats==['text','html'])