← All notes

Flask renders Jinja templates and autoescapes HTML by default

Answer: Flask uses Jinja as its template engine. You may use a different engine in your own code, but Jinja still has to be installed because Flask and its extensions depend on it. Call render_template with a template name and context variables.

Default setup

Unless you change it, autoescaping is on for templates whose names end in .html, .htm, .xml, .xhtml, and .svg when you use render_template, and for every string passed to render_template_string. Templates can also opt in or out with the {% autoescape %} tag. By default, templates can use config, request, session, g, url_for, and get_flashed_messages. Those values are context variables, not true Jinja globals, so imported macros need with context or an explicit argument to see request.

The helpers in source

render_template renders a template by name with the given context, or the first name in a list that exists. Flask's Jinja Environment works like a regular Jinja environment, with extra knowledge of blueprints so a referenced template can get the blueprint's name prepended.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Flask documentation and source (pallets/flask): Copyright 2010 Pallets; BSD-3-Clause (https://raw.githubusercontent.com/pallets/flask/main/LICENSE.txt). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Flask docs and Flask source (pallets/flask), BSD-3-Clause (https://raw.githubusercontent.com/pallets/flask/main/LICENSE.txt). Notices: Flask documentation and source (pallets/flask): Copyright 2010 Pallets; BSD-3-Clause (https://raw.githubusercontent.com/pallets/flask/main/LICENSE.txt).

Cite this

Permanent ID: iil:note:4hwqnv87

iinventedlight. 2026. "Flask renders Jinja templates and autoescapes HTML by default." iinventedlight Library, iil:note:4hwqnv87, version of 2026-11-11. https://iinventedlight.com/library/notes/flask-templates/. License: CC-BY-4.0.

@misc{iil_note_4hwqnv87,
  author = {{iinventedlight}},
  title = {{Flask renders Jinja templates and autoescapes HTML by default}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-11},
  url = {https://iinventedlight.com/library/notes/flask-templates/},
  note = {Permanent ID iil:note:4hwqnv87. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/flask-templates.md.