#37015 closed New feature (duplicate)
Improve template debugging by showing missing context variables and suggestions
| Reported by: | Butool Fatima | Owned by: | |
|---|---|---|---|
| Component: | Template system | Version: | 6.0 |
| Severity: | Normal | Keywords: | template debugging, error reporting, undefined variables, developer experience, suggestion, debug mode |
| Cc: | Butool Fatima | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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_MODEto 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.
Attachments (2)
Change History (4)
by , 3 weeks ago
| Attachment: | Screenshot 2026-03-31 100327.png added |
|---|
by , 3 weeks ago
| Attachment: | Screenshot 2026-03-31 100511.png added |
|---|
comment:1 by , 3 weeks ago
| Has patch: | unset |
|---|---|
| Resolution: | → needsnewfeatureprocess |
| Status: | new → closed |
comment:2 by , 3 weeks ago
| Resolution: | needsnewfeatureprocess → duplicate |
|---|
The idea of making undefined variables raise an exception is a duplicate of #28618.
Hello Butool Fatima, thank you for your interest in Django. Before making any further submission, I recommend reading 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 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 the documented guidelines for requesting features.