How to load jinja template directly from filesystem

前端 未结 4 725
挽巷
挽巷 2020-12-12 23:43

The jinja API document at pocoo.org states:

The simplest way to configure Jinja2 to load templates for your application looks roughly like this:
4条回答
  •  遥遥无期
    2020-12-12 23:45

    A simpler way is to directly call the jinj2.Template constructor and use open to load the file:

    from jinja2 import Template
    with open('template.html.jinja2') as file_:
        template = Template(file_.read())
    template.render(name='John')
    

提交回复
热议问题