To reproduce:
base.html:
{{{
{% block body %}{% endblock %}
}}}
home.html:
{{{
{% extends "base.html" %}
{% block body %}
{% include "does_not_exist" %}
{% endblock %}
}}}
views.py:
{{{
from django.shortcuts import render
def home(request):
return render(request, 'home.html')
}}}
The resulting error page displays:
{{{
Error during template rendering
In template
/Users/matthew/Development/tbx/wagtail/debug/brokendebug/core/templates/base.html,
error at line 0
does_not_exist
1 {% block body %}{% endblock %}
2
}}}
instead of the expected error output:
{{{
Error during template rendering
In template
/Users/matthew/Development/tbx/wagtail/debug/brokendebug/core/templates/home.html,
error at line 4
does_not_exist
1 {% extends "base.html" %}
2
3 {% block body %}
4 {% include "does_not_exist" %}
5 {% endblock %}
6
}}}
Bisecting shows that this bug was introduced in #27956
(e643ba8bcf0b1da517cbab689ac157ee031202a3), which was a fix for the
''opposite'' case: an error occurring on the parent template. (In the
above test case, moving the line `{% include "does_not_exist" %}` to
base.html turns it into a test case for #27956, and fails on pre-
e643ba8bcf0b1da517cbab689ac157ee031202a3 revisions as expected.)
--
Ticket URL: <https://code.djangoproject.com/ticket/28935>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Preston Timmons (added)
* component: Uncategorized => Template system
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:1>
* status: new => assigned
* owner: nobody => Alexander Vyushkov
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:2>
* owner: Alexander Vyushkov => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:3>
* cc: Collin Anderson (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:4>
* owner: (none) => Ankur Jain
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:5>
Comment (by Ankur Jain):
When the parser runs then it appends all the child template nodes to the
parent template nodes and hence when template not found error comes then
it's reported from the parent html instead of the child html.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:6>
Comment (by Simon Charette):
#29740 was a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:7>
Comment (by Michael F. Lamb):
Replying to [comment:6 Ankur Jain]:
Hi, I'm interested in working on this bug. Are you still working on it,
Ankur?
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:8>
* cc: pascal chambon (added)
Comment:
Error confirmed on Django2.2.1, it makes the debug page much less helpful
in case of TemplateError, since most websites inherit their templates from
some kind of "base.html" skeleton.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:9>
Comment (by Simone Lazzaris):
Bug still present in 2.2.3; if you (like me) use a tree-structured number
of small template files it is very VERY annoying as you have to guess
where the bug you're chasing is between the various parts.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:10>
* cc: Simone Lazzaris (added)
* version: 2.0 => 2.2
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:11>
* owner: Ankur Jain => (none)
* status: assigned => new
* version: 2.2 => master
Comment:
Simone, patch is welcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:12>
* cc: Min ho Kim (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:13>
* owner: (none) => Min ho Kim
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:14>
* owner: Min ho Kim => (none)
* status: assigned => new
Comment:
I'm deassigning myself for now so someone else can have a go until I can
come back in the future.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:15>
* owner: (none) => Ashutosh Sharma
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:16>
* owner: Ashutosh Sharma => (none)
* status: assigned => new
Comment:
I couldn't find a way to fix this bug. Deassigning so someone else can
have a try.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:17>
* owner: (none) => Zahid92
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:18>
Comment (by felixxm):
#31478 was a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:19>
* owner: Zahid Hussain Ansari => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:20>
* owner: (none) => cammil
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:21>
Comment (by cammil):
Think I have an idea how to fix this. Going to do some more testing to
make sure.
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:22>
Comment (by cammil):
I've created a PR:
https://github.com/django/django/compare/main...cammil:ticket_27694
Does anyone have any comments or feedback?
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:23>
* cc: cammil (added)
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:24>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:25>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"313c3d1aa14d80922003f841c257ec4e153f8653" 313c3d1]:
{{{
#!CommitTicketReference repository=""
revision="313c3d1aa14d80922003f841c257ec4e153f8653"
Fixed #28935 -- Fixed display of errors in extended blocks.
Get the template that caused the exception and get the
exception info from that template, using the node that
caused the exception.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28935#comment:26>