﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37015	Improve template debugging by showing missing context variables and suggestions	Butool Fatima		"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.
"	New feature	closed	Template system	6.0	Normal	duplicate	template debugging, error reporting, undefined variables, developer experience, suggestion, debug mode	Butool Fatima	Unreviewed	0	0	0	0	0	0
