Opened 6 years ago

Closed 19 months ago

#14343 closed Cleanup/optimization (fixed)

NoReverseMatch error message is unclear, view does exist

Reported by: Diederik van der Boor Owned by: nobody
Component: Core (URLs) Version: 1.2
Severity: Normal Keywords: url, resolver
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As Django newcomer, the NoReverseMatch error appears confusing to me.
It took me about 1 hour to figure out my problem because the error message was unclear.
This might not be technically a bug but I believe this is a "user experience" bug.

This is the error message:

Caught NoReverseMatch while rendering: Reverse for 'webgtd-contexts-index' with arguments '()' and keyword arguments '{}' not found.

The line in error was:

<a accesskey="c" href="{% url webgtd-contexts-index %}">

The URLConf has the following entry:

    url(r'^contexts/(?P<id>\d*)$', 'todo.by_context', name='webgtd-contexts-index'),

The todo view looked like like:

def by_context(request, id=0):
    return index(request)

In my reasoning this parameter would be optional, but I was wrong.
The function signature looked fine to me, which made the error message confusing.

I've rewritten the regex now as: '^contexts/(?P<id>\d+)?$'.

Could you please improve the error message, so that it either:

  • ...mentions the view function does not exist at all.
  • ...mentions the view function does exist, but requires more parameters
  • ...mentions the URLconf regex pattern requires more parameters

Change History (10)

comment:1 Changed 6 years ago by dmoisset

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Graham King

Keywords: url resolver added
Severity: Normal
Type: Uncategorized

comment:3 Changed 5 years ago by Julien Phalip

Type: UncategorizedCleanup/optimization

comment:4 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 4 years ago by Aymeric Augustin

Component: Core (Other)Core (URLs)

comment:7 Changed 4 years ago by Aymeric Augustin

#19091 was a duplicate.

comment:8 Changed 4 years ago by Aymeric Augustin

#18373 is related.

comment:9 Changed 3 years ago by Wilfred

#17076 is related.

comment:10 Changed 19 months ago by Bas Peschier

Resolution: fixed
Status: newclosed

I am going to close this on the basis that the NoReverseMatch now contains the tried pattern(s):

django.core.urlresolvers.NoReverseMatch: Reverse for 'webgtd-contexts-index' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['contexts/(?P<id>\\d*)$']

This means the NoReverseMatch is no longer a complete dead end: it now provides a bit of information where to look. Since there are a lot of reasons the pattern could not match (especially now we support lookarounds), it is going to be very difficult to provide more information.

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