---
source: https://iinventedlight.com/library/notes/flask-templates.md
title: "Flask renders Jinja templates and autoescapes HTML by default"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (pallets/flask docs and source); prose restates cited source lines in own words"
license_family: flask-bsd3
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-11
status: published
approved_by: "Cole Withington, 2026-11-11 17:50 PT, Librarian chat widget t44s275: \"Yes, publish all 8 gap drafts\""
approved_by: "Cole Withington, 2026-11-11 17:59 PT, Engineer chat widget t716s3194: \"Yes, publish all 8 gap notes live\""
checked_on: 2026-11-11
as_of: 2026-11-11
confidence: medium
untested: "No Flask project was run for this note; only the fetched documentation and source files were read."
category: coding-references
topic_area: "code-backend: Flask templates"
tags: [flask, jinja, templates, autoescape]
client: Librarian
sources:
  - id: S1
    title: "Templates"
    publisher: Flask docs
    url: https://flask.palletsprojects.com/en/stable/templating/
    accessed: 2026-11-11
    license: "BSD-3-Clause"
  - id: S2
    title: "flask.templating"
    publisher: Flask source
    url: https://github.com/pallets/flask/blob/main/src/flask/templating.py
    accessed: 2026-11-11
    license: "BSD-3-Clause"
---
# 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

- [flask-application](https://iinventedlight.com/library/notes/flask-application/)
- [flask-blueprints](https://iinventedlight.com/library/notes/flask-blueprints/)

## Claims

- id: C1
  claim: Flask uses Jinja as its template engine.
  source: S1
  evidence: "Flask leverages Jinja as its template engine."

- id: C2
  claim: Autoescaping is on for HTML and similar suffixes when rendering a template file.
  source: S1
  evidence: "autoescaping is enabled for all templates ending in ``.html``,"

- id: C3
  claim: render_template renders a template by name with the given context.
  source: S2
  evidence: "Render a template by name with the given context."

- id: C4
  claim: Flask's Jinja environment is aware of blueprints when resolving templates.
  source: S2
  evidence: "Works like a regular Jinja environment but has some additional"

## Sources

- [S1] Templates. Flask docs. https://flask.palletsprojects.com/en/stable/templating/ . License: BSD-3-Clause. Accessed 2026-11-11.

- [S2] flask.templating. Flask source. https://github.com/pallets/flask/blob/main/src/flask/templating.py . License: BSD-3-Clause. Accessed 2026-11-11.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
