Opened 7 weeks ago
Closed 5 weeks ago
#35789 closed Cleanup/optimization (fixed)
Improve non-first {% extends %} error message
Reported by: | Adam Johnson | Owned by: | Ekin Ertaç |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Currently if you put {% extends %}
after another tag, the error looks like:
TemplateSyntaxError: <ExtendsNode: extends 'base.html'> must be the first tag in the template.
ExtendsNode
is a leaked internal detail. Showing its repr() is a bit confusing, especially for a beginner programmer.
The message would be clearer if it showed the actual text of the tag:
TemplateSyntaxError: {% extends 'base.html' %} must be the first tag in the template.
Change History (9)
comment:1 by , 7 weeks ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 7 weeks ago
comment:4 by , 7 weeks ago
The repr should not be changed, it’s still used in other contexts like debugging. Change the error message to show/build the extends tag source.
comment:5 by , 7 weeks ago
Has patch: | set |
---|
comment:6 by , 6 weeks ago
Just sent a PR to github to add a clear error message. https://github.com/django/django/pull/18653
comment:7 by , 5 weeks ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
comment:8 by , 5 weeks ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
So After looking at the code I am a bit stuck on what should be done, the error message is constructed using the
__repr__
method ofExtendNode
classAnd this is the
__repr__
functionI don't think changing the repr method or hard coding the error message is any better. So what should be done ?