📜  jinja 渲染模板到文件 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:44.395000             🧑  作者: Mango

代码示例1
from jinja2 import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('test.html')

output_from_parsed_template = template.render(foo='Hello World!')
print(output_from_parsed_template)

# to save the results
with open("my_new_file.html", "w") as fh:
    fh.write(output_from_parsed_template)