Opened 3 months ago
Closed 2 months 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 , 3 months ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 3 months ago
comment:4 by , 3 months 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 , 3 months ago
Has patch: | set |
---|
comment:6 by , 2 months ago
Just sent a PR to github to add a clear error message. PR
Edit:
I didn't notice the first PR, sorry about that.
comment:7 by , 2 months ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
comment:8 by , 2 months 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 ?