def render_template(context, template, path=None, executable=False):
"""
Renders the ``template`` template with the given ``context``. The result is
written to ``path``. If ``path`` is not specified, the result is
returned as a string
"""
env = _init_template_env()
data = env.get_template(template).render(context)
if not path:
return data
with open(path, 'w') as f:
f.write(data)
if executable:
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
评论列表
文章目录