Hi all,
I am applying to GSoC for the first time.
I’ve drafted a proposal for the template missing variable behavior idea. I intend to introduce Jinja2-inspired Undefined strategy system (Undefined, PlaceholderUndefined, StrictUndefined), scoped by default to project templates only, with an opt-in global override and a block-level {% undefined %} tag modeled on {% autoescape %}.
I’d appreciate feedback, especially on the scoping approach.
Thanks!
GSoC-2026-Proposal.md
Add Ergonomic Control Over Behavior of Missing Variables in Django Templates using configurable jinja2 inspired undefined strategies.
## Summary
Django’s template system currently **silently converts missing variables to an empty string**. While this design enables fault-tolerant rendering and flexible templates which is usually expected for production, it creates significant challenges for debugging, correctness, and developer ergonomics.
Currently Django's template engine offers only one mechanism for controlling missing variable behaviour: the global `string_if_invalid` setting. This setting is well-documented to be dangerous, fragile, and unsuitable for anything beyond narrow, temporary debugging use.
This proposal introduces a Jinja2-inspired `Undefined` strategy system with three design goals: safe by default (applied to project templates only, leaving third-party templates unaffected), opt-in globally via `apply_undefined_globally`, and overridable at the block level via a new `{% undefined %}` tag. Together, these mechanisms give developers precise, composable control over missing-variable behavior without sacrificing backward compatibility.
This file has been truncated. show original
1 Like