[Django] #37015: Improve template debugging by showing missing context variables and suggestions

11 views
Skip to first unread message

Django

unread,
Mar 31, 2026, 12:30:15 AMMar 31
to django-...@googlegroups.com
#37015: Improve template debugging by showing missing context variables and
suggestions
-------------------------------------+-------------------------------------
Reporter: coder_787 | Type: New
| feature
Status: new | Component: Template
| system
Version: 6.0 | Severity: Normal
Keywords: template debugging, | Triage Stage:
error reporting, undefined | Unreviewed
variables, developer experience, |
suggestion, debug mode |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When working with Django templates, missing or undefined context variables
often fail silently or provide limited debugging information. This makes
it difficult to quickly identify the source of the issue.

For example:

```django
{{ user.email }}
```

If `user` or `email` is missing, Django does not clearly indicate which
variable is missing, where it originated, or whether a similar variable
exists in the context.

This proposal aims to improve template debugging by enhancing the error
reporting system in DEBUG mode.

The suggested improvements include:

* Detecting missing or undefined variables during template rendering
* Showing the missing variable name
* Indicating the template file and line number where the issue occurs
* Providing suggestions for similar variable names from the context (e.g.,
`emial` → `email`)
* Optionally introducing a setting like `STRICT_TEMPLATE_MODE` to raise
explicit errors for undefined variables

Example output:

```
Template Variable Error:
- Variable 'emial' not found in context
- Did you mean: 'email'?
- Template: profile.html, line 12
```

Benefits:

* Improves debugging experience
* Helps developers identify issues faster
* Reduces silent failures in templates
* Makes Django more beginner-friendly

Potential concerns:

* Performance impact (can be limited to DEBUG mode)
* Backward compatibility (can be optional via settings)

Implementation notes:

* Extend template variable resolution logic
* Integrate with existing error handling (e.g., VariableDoesNotExist)
* Use string similarity to suggest variable names
* Enable via settings or DEBUG mode only

A prototype of this feature has been implemented locally and is ready for
feedback and further refinement.
--
Ticket URL: <https://code.djangoproject.com/ticket/37015>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 31, 2026, 12:37:03 AMMar 31
to django-...@googlegroups.com
#37015: Improve template debugging by showing missing context variables and
suggestions
-------------------------------------+-------------------------------------
Reporter: coder_787 | Owner: (none)
Type: New feature | Status: new
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: template debugging, | Triage Stage:
error reporting, undefined | Unreviewed
variables, developer experience, |
suggestion, debug mode |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coder_787):

* Attachment "Screenshot 2026-03-31 100327.png" added.

Django

unread,
Mar 31, 2026, 12:37:03 AMMar 31
to django-...@googlegroups.com
#37015: Improve template debugging by showing missing context variables and
suggestions
-------------------------------------+-------------------------------------
Reporter: coder_787 | Owner: (none)
Type: New feature | Status: new
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: template debugging, | Triage Stage:
error reporting, undefined | Unreviewed
variables, developer experience, |
suggestion, debug mode |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coder_787):

* Attachment "Screenshot 2026-03-31 100511.png" added.

Django

unread,
Mar 31, 2026, 8:13:18 AMMar 31
to django-...@googlegroups.com
#37015: Improve template debugging by showing missing context variables and
suggestions
-------------------------------------+-------------------------------------
Reporter: Butool Fatima | Owner: (none)
Type: New feature | Status: closed
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: template debugging, | needsnewfeatureprocess
error reporting, undefined | Triage Stage:
variables, developer experience, | Unreviewed
suggestion, debug mode |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* has_patch: 1 => 0
* resolution: => needsnewfeatureprocess
* status: new => closed

Comment:

Hello Butool Fatima, thank you for your interest in Django. Before making
any further submission, I recommend reading
[https://docs.djangoproject.com/en/dev/internals/contributing.html the
Django Contributing Guide]. In this guide you will find details for the
right process to propose a new feature for Django. Also, please avoid use
of LLM when making these submissions.

The new feature idea should first be proposed and discussed with the
community. To do that, please raise this on the [https://github.com/django
/new-features/issues ​new feature tracker]. I'll close the ticket for now,
but if the community agrees with the proposal, please return to this
ticket and reference the forum discussion so we can re-open it. For more
information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].
--
Ticket URL: <https://code.djangoproject.com/ticket/37015#comment:1>

Django

unread,
Mar 31, 2026, 8:53:14 AMMar 31
to django-...@googlegroups.com
#37015: Improve template debugging by showing missing context variables and
suggestions
-------------------------------------+-------------------------------------
Reporter: Butool Fatima | Owner: (none)
Type: New feature | Status: closed
Component: Template system | Version: 6.0
Severity: Normal | Resolution: duplicate
Keywords: template debugging, | Triage Stage:
error reporting, undefined | Unreviewed
variables, developer experience, |
suggestion, debug mode |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* resolution: needsnewfeatureprocess => duplicate

Comment:

The idea of making undefined variables raise an exception is a duplicate
of #28618.
--
Ticket URL: <https://code.djangoproject.com/ticket/37015#comment:2>
Reply all
Reply to author
Forward
0 new messages