Opened 3 days ago
Last modified 3 hours ago
#35789 assigned Cleanup/optimization
Improve non-first {% extends %} error message
Reported by: | Adam Johnson | Owned by: | Mohamed Nabil Rady |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
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 (5)
comment:1 by , 41 hours ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed β Accepted |
comment:2 by , 30 hours ago
Owner: | set to |
---|---|
Status: | new β assigned |
comment:3 by , 12 hours ago
comment:4 by , 10 hours 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 hours ago
Has patch: | set |
---|
Note:
See TracTickets
for help on using tickets.
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 ?