#29399 closed Bug (duplicate)
Template rendering errors are incorrectly blamed on base template
Reported by: | oTree-org | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Repro steps:
- create a "base.html"
- create a "child.html" that inherits from base.html with
{% extends %}
put one of the following lines child.html:
{% url 'nonexistent' %}
{% include 'nonexistent.html' %}
Expected: the yellow error page's "template debug" context should highlight the offending line, as it does when you have a TemplateSyntaxError during compilation.
Actual: the error page incorrectly blames base.html, and says the error is at line 0:
"Error during template rendering
In template ...\base.html, error at line 0"
It then shows the first 10 lines of base.html, but of course there is no error there.
I think this is caused by django.template.base.Node.render_annotated
, specifically this line:
e.template_debug = context.render_context.template.get_exception_info(e, self.token)
It seems fixed if I change it to:
e.template_debug = context.template.get_exception_info(e, self.token)
(I got the idea because I saw context.template
referenced on the previous line.)
You can run the attached project which reproduces the issue (run server and open to /).
Attachments (1)
Change History (4)
by , 7 years ago
Attachment: | missing_template_vars.zip added |
---|
comment:2 by , 7 years ago
Furthermore, it seems that if template C extends B, which extends A, then errors in B will not be pinpointed correctly in either case (whether using context
or context.render_context
).
I found this related bug: #27584.
It seems that if the line is written the other way, it conceals problems in the *parent* template.