Unclear Debug Message (Bug?) When Invalid Url in Extended Template

45 views
Skip to first unread message

Connor Boyle

unread,
Jan 21, 2017, 6:02:27 PM1/21/17
to Django users
I've noticed that when I extend a template that references an invalid url name, in debug mode, the error message doesn't highlight the erroneous line in the parent template, but rather shows a section of the child template.

For example if "base.html" is just:

{% block content %}{% endblock %}
<a href="{% url 'page_three' %}">Page Three</a>

And "page_one.html" is:

{% extends 'base.html' %}
{% block content %}<p>This is page one</p>{% endblock %}

when there is no url named "page_three", debug mode will show an error message entitled:

NoReverseMatch at /page_one/
Reverse for 'page_three' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

and show a few lines of page_one.html (instead of base.html, where the error originated). See attached screenshot for example.

Debug mode seems to do a fine job of highlighting the invalid line in the parent template for other errors, such as an {% if %} without an {% endif %} or an unrecognized tag (e.g. {% asdf %} ).

Is this a bug? Or at least a sorely missing feature? Am I crazy for thinking that this is not how this error should be displayed?
Screen Shot 2017-01-21 at 4.57.19 PM.png

Tim Graham

unread,
Jan 23, 2017, 8:31:22 PM1/23/17
to Django users
Could you check with Django 1.11a1? This might be fixed in https://code.djangoproject.com/ticket/27584.

Connor Boyle

unread,
Jan 28, 2017, 11:04:42 PM1/28/17
to Django users
Does not appear to be fixed in Django 1.11a1.
Screen Shot 2017-01-28 at 9.15.53 PM.png

Connor Boyle

unread,
Jan 28, 2017, 11:10:40 PM1/28/17
to Django users
Django 1.8 produces a reasonable error message (highlighting the problematic line in the relevant template file–though the formatting is a little odd), however Django 1.9 has the same problem as 1.10 and 1.11a.
Screen Shot 2017-01-28 at 9.19.16 PM.png
Screen Shot 2017-01-28 at 9.18.31 PM.png
Screen Shot 2017-01-28 at 9.18.21 PM.png

Tim Graham

unread,
Jan 30, 2017, 9:52:59 AM1/30/17
to Django users
Thanks. Please create a ticket with details:
https://code.djangoproject.com/newticket
Reply all
Reply to author
Forward
0 new messages