Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#8251 closed (duplicate)

Receiving NoReverseMatch using {% url %} and Generic Views

Reported by: Bryan Veloso Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: ega641@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My project uses only generic views with named URL patterns. After updating to [8317] tonight, I ran into an error probably related to the [8211] NoReverseMatch exception change. Before the update, my {% url %} tags, which consist of only a single argument, e.g. {% url project-list %} return the following error:

Traceback (most recent call last):, referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 216, in __call__, referer: http://djangoplugables.com/
    response = self.get_response(request), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 125, in get_response, referer: http://djangoplugables.com/
    return self.handle_uncaught_exception(request, resolver, exc_info), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 157, in handle_uncaught_exception, referer: http://djangoplugables.com/
    return callback(request, **param_dict), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/views/defaults.py", line 89, in server_error, referer: http://djangoplugables.com/
    return http.HttpResponseServerError(t.render(Context({}))), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 176, in render, referer: http://djangoplugables.com/
    return self.nodelist.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 751, in render, referer: http://djangoplugables.com/
    bits.append(self.render_node(node, context)), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 764, in render_node, referer: http://djangoplugables.com/
    return node.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py", line 97, in render, referer: http://djangoplugables.com/
    return compiled_parent.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 176, in render, referer: http://djangoplugables.com/
    return self.nodelist.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 751, in render, referer: http://djangoplugables.com/
    bits.append(self.render_node(node, context)), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 764, in render_node, referer: http://djangoplugables.com/
    return node.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 29, in render, referer: http://djangoplugables.com/
    output = self.nodelist.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 751, in render, referer: http://djangoplugables.com/
    bits.append(self.render_node(node, context)), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 764, in render_node, referer: http://djangoplugables.com/
    return node.render(context), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 369, in render, referer: http://djangoplugables.com/
    args=args, kwargs=kwargs), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 307, in reverse, referer: http://djangoplugables.com/
    *args, **kwargs))), referer: http://djangoplugables.com/
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 291, in reverse, referer: http://djangoplugables.com/
    raise NoReverseMatch("Reverse for '%s' not found." % lookup_view), referer: http://djangoplugables.com/
NoReverseMatch: Reverse for 'settings.project-list' not found., referer: http://djangoplugables.com/

What bugs me here is that it is looking in settings.project-list. Why would it be looking in the settings for a named URL argument? I was told that this could be a bug and I am reporting it as such. Please do not complicate matters by trying to find something more complex. I am merely using generic views and named arguments, and I am receiving these errors.

Change History (13)

comment:1 by Julien Phalip, 16 years ago

milestone: 1.0 beta1.0

We'd need a bit more info to debug this. Could you post your URLConf and views? Even better would be a test case reproducing the issue.

comment:2 by Malcolm Tredinnick, 16 years ago

It looks like the error is just being misreported, but it's still an error. If you look at the code in question (the changes in [8211]), you'll see that if a named pattern match fails, it then makes a final attempt to do "project name + function name" (for better or worse). Since you're not running in a project situation (it looks like your settings value is just settings here), the final step tries a project name of "settings". That's invalid, but it indicates that you've already failed to have a pattern match.

So it looks like some more care is needed with the error message construction here and that seems to be the way to resolve this ticket.

You don't indicate whether the {% url ... %} call in question worked (in the sense of "actually matched a pattern") previously or not. Looking at the changes in [8211] and where the exception is raised, I'd guess that it returned the empty string before, which is a result of not matching anything. If so, raising an error of some kind there is consistent with the intended effect of [8211].

comment:3 by floguy, 16 years ago

This error is coming from the open source DjangoPlugables codebase.

The template in question is http://github.com/revyver/django-plugables/tree/master/templates/base.html

The URL that it should map to is: http://github.com/revyver/django-plugables/tree/master/applications/projects/urls.py

I was trying to go through and debug this error myself, but couldn't see why it should be failing. On twitter, Brian Rosner mentioned that he believes it could be related to #8246

comment:4 by Brian Rosner, 16 years ago

It is late and I saw an exception and the word settings. It was simply a shot in the dog FWIW ;)

in reply to:  4 comment:5 by floguy, 16 years ago

Replying to brosner:

It is late and I saw an exception and the word settings. It was simply a shot in the dog FWIW ;)

Oh please tell me you didn't shoot your dog.

comment:6 by Bryan Veloso, 16 years ago

@Malcolm: I didn't? Hah, late and distressed I guess. But yes, to back up Eric, it DID work previously.

comment:7 by Jacob, 16 years ago

Triage Stage: UnreviewedAccepted

comment:8 by Brian Rosner, 16 years ago

I haven't been able to track this down precisely yet, but what I have discovered can be useful. This exception only occurs when DEBUG is False. When DEBUG is True the real error is shown which was a third party app still using newforms references. Somehow this is getting masked.

comment:9 by anonymous, 16 years ago

Cc: ega641@… added

when i wite {% url django.contrib.auth.views.login %} in template, django show me error Caught an exception while rendering: Reverse for 'my_project.contrib.auth.views.login' not found.

Why it appends my_project? Is it a bug?

in reply to:  9 comment:10 by anonymous, 16 years ago

Replying to anonymous:

when i wite {% url django.contrib.auth.views.login %} in template, django show me error Caught an exception while rendering: Reverse for 'my_project.contrib.auth.views.login' not found.

Why it appends my_project? Is it a bug?

Oh, sorry, the error is Caught an exception while rendering: Reverse for 'my_project.django.contrib.auth.views.login' not found.

comment:11 by Andrew Stoneman, 16 years ago

Component: UncategorizedCore framework

in reply to:  8 comment:12 by James Bennett, 16 years ago

Resolution: duplicate
Status: newclosed

Replying to brosner:

I haven't been able to track this down precisely yet, but what I have discovered can be useful. This exception only occurs when DEBUG is False. When DEBUG is True the real error is shown which was a third party app still using newforms references. Somehow this is getting masked.

If that's the case, this is a dupe of #7524.

comment:13 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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