render jinja2 template without a Flask context

前端 未结 3 591
醉酒成梦
醉酒成梦 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条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 04:53

    You need to render it in an app context. Import your app in your backend code and do the following.

    with app.app_context():
        data = render_template(path, **context)
    

提交回复
热议问题