render jinja2 template without a Flask context

前端 未结 3 583
醉酒成梦
醉酒成梦 2021-01-02 03:59

I have a Flask application that calls flask.render_template without problems when it is invoked from a flask http request.

I need the same

3条回答
  •  Happy的楠姐
    2021-01-02 04:36

    If you want to completely bypass flask and use purely Jinja for rendering your template, you can do as such

    import jinja2
    
    def render_jinja_html(template_loc,file_name,**context):
    
        return jinja2.Environment(
            loader=jinja2.FileSystemLoader(template_loc+'/')
        ).get_template(file_name).render(context)
    

    And then you can call this function to render your html

提交回复
热议问题