Opened 12 years ago

Closed 12 years ago

#19091 closed Cleanup/optimization (duplicate)

NoReverseMatch template errors are difficult to debug

Reported by: Alper Cugun Owned by: nobody
Component: Core (URLs) Version: 1.4
Severity: Normal Keywords:
Cc: HM Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

I've been using django for ages and I'd never really used {% url %} before and now I know why. First the transition to 1.5 URL names' and the rest of the documentation is a bit of a mess, but that is not what this bug is about.

If your URL tag can't find something useful this is the error message you receive:

NoReverseMatch at /
Reverse for 'topic_detail' with arguments '(2, u'professor-wever')' and keyword arguments '{}' not found.

(Full paste log attached.)

For somebody not wholly familiar with this system this error message which only outputs a traceback from the template renderer this error message is not very helpful. Could this be improved? (Not for me I've learnt my lesson, but I imagine this is going to cause tons of frustration to any new learners.)

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.4
Python Version: 2.7.1
Installed Applications:
('django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'boogie',
'django.contrib.admin')

Installed Middleware:
('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Template error:
In template /Users/alper/Documents/projects/sake/victory/templates/boogie/index.html, error at line 8

Reverse for 'topic_detail' with arguments '(2, u'professor-wever')' and keyword arguments '{}' not found.
1 : {% extends "base.html" %}

2 : {% load url from future %}

3 :

4 : {% block content %}

5 : <h1>Frontpage</h1>

6 :

7 : {% for topic in topics %}

8 : Onderwerp: <a href=" {% url 'topic_detail' topic.id topic.slug %} ">{{ topic.title }}</a><br>

9 : {% endfor %}

10 :

11 : <h1>Bijdragen</h1>

12 :

13 : {% for piece in pieces %}

14 : {{ piece.text }}<br>

15 : {% endfor %}

16 :

17 : {% endblock %}

Traceback:
File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/Users/alper/Documents/projects/sake/victory/boogie/views.py" in index

  1. return HttpResponse(t.render(c))

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in render

  1. return self._render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in render

  1. bit = self.render_node(node, context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node

  1. return node.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/loader_tags.py" in render

  1. return compiled_parent._render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in render

  1. bit = self.render_node(node, context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node

  1. return node.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/loader_tags.py" in render

  1. result = block.nodelist.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/base.py" in render

  1. bit = self.render_node(node, context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node

  1. return node.render(context)

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/defaulttags.py" in render

  1. nodelist.append(node.render(context))

File "/Users/alper/Documents/projects/sake/victory/venv/lib/python2.7/site-packages/django/template/defaulttags.py" in render

  1. raise e

Exception Type: NoReverseMatch at /
Exception Value: Reverse for 'topic_detail' with arguments '(2, u'professor-wever')' and keyword arguments '{}' not found.

Attachments (1)

pastelog.txt (4.1 KB ) - added by Alper Cugun 12 years ago.

Download all attachments as: .zip

Change History (5)

by Alper Cugun, 12 years ago

Attachment: pastelog.txt added

comment:1 by Preston Holmes, 12 years ago

Summary: NoReverseMatch template errors are impossible to debugNoReverseMatch template errors are difficult to debug
Triage Stage: UnreviewedAccepted

Always worth improving error messages

comment:2 by Chris Wilson, 12 years ago

There's a monkey patch here that improves debugging messages in reverse:

https://github.com/aptivate/intranet-binder/blob/master/monkeypatches.py#L203

If this looks reasonable I can try to work up a patch. It does need to be updated because since Django 1.4 the RegexURLResolver.reverse method that it patches has a new name.

comment:3 by HM, 12 years ago

Cc: HM added

This is what I find to be the most annoying error in Django (1.5) right now. There's currently over 33 000 ghits and 281 questions on Stackoverflow mentioning it.

gcc, that link leads to a 404.

comment:4 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: newclosed

This was already reported as #14343.

Unfortunately the GitHub link above returns a 404 — which is rather ironic for a bug about NoReverseMatch ;) — so there isn't much content in this ticket that isn't already in #14343.

Note: See TracTickets for help on using tickets.
Back to Top