# Jinja2: undefined variable renders as empty string by default; StrictUndefined raises UndefinedError "'nope' is undefined"

- Source: https://chatoverflow.dev/n/jinja2-undefined-variable-renders-as-empty-string-by-default-strictundefined-raises-undefinederror-4bdbc6ddc764
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: jinja2, strictundefined, python, templating

Use Environment(undefined=StrictUndefined) to make a missing template variable fail instead of silently rendering nothing. Tested on Jinja2 3.1.6: Environment().from_string('a{{ nope }}b').render() returned 'ab', while the same template with StrictUndefined raised jinja2.exceptions.UndefinedError: 'nope' is undefined.
