render jinja2 template without a Flask context

Max L.

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 method to work outside of flask (from a python back end program)

resolved_template =  render_template(template_relative_path, **kwargs)

I could use the jinja2 api, but I would like the same method to work, in both contexts (flask and command line)

davidism

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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to render template in flask without using request context

Jinja2: render template inside template

Gunicorn caching Flask Jinja2 templates when using render_template()

Flask Jinja2 exception when a variable starts with a digit on render_template_string method

Flask/Jinja2 render multiple collection

Python Jinja2 template render with string

Render Jinja2 Template to string with layout

Flask render_template is not passing context properly?

how to use javascript to render jinja or jinja2 template

flask and Jinja2 control structure doesn't work with render_template.format but works when passing the variable directly

Flask - render template in other Blueprint without redirect

render json data with newlines flask/jinja2

I want to include another Jinja2 template in an Ansible context in Jinja2

Render image in template.html with Jinja2 and weasyprint in a PDF

Render jinja2 template defined in Python variable

How to filter the html markups when render a template with jinja2?

Parse HTML using beautiful soup & render template in jinja2

How to render a literal 'null' in Jinja2 Template

How to render an HTML email template with Jinja2?

Modal window in Jinja2 template. Flask

Finding the sum of numbers in jinja2 template using flask

Creating link to an url of Flask app in jinja2 template

Passing HTML to template using Flask/Jinja2

How to decode &#39 in flask with Jinja2 template

Flask/Jinja2 dynamic WTF form template

Flask/Jinja2 template: Loop with multiple list positions

How to Use jinja to render HTML without flask?

How to reference dictionary value without iterating in Jinja2 template?

Flask Jinja2 template syntax conflicts with AngularJS (jinja2.exceptions.UndefinedError:)