jinja2的模板里写入python变量
def createReport(content):
env = Environment(
line_statement_prefix = "#",
# variable_start_string = "${",
# variable_end_string = "}"
)
f = open( "report.html","w" )
f.write(
env.from_string("""\
<html>
<ul>
<li>{{content}}</li>
</ul>
</html>
\
""").render(content=content)
)
?
其中?render(content=content) 就是将python里的变量替换到模板中的变量中去。