Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8251 closed (duplicate)

Receiving NoReverseMatch using {% url %} and Generic Views

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

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.

Attachments (0)

Change History (13)

comment:1 Changed 6 years ago by julien

  • milestone changed from 1.0 beta to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 6 years ago by mtredinnick

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 Changed 6 years ago by floguy

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 follow-up: Changed 6 years ago by brosner

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

comment:5 in reply to: ↑ 4 Changed 6 years ago by floguy

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 Changed 6 years ago by bryanveloso

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

comment:7 Changed 6 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:8 follow-up: Changed 6 years ago by 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.

comment:9 follow-up: Changed 6 years ago by anonymous

  • 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?

comment:10 in reply to: ↑ 9 Changed 6 years ago by anonymous

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 Changed 6 years ago by astoneman

  • Component changed from Uncategorized to Core framework

comment:12 in reply to: ↑ 8 Changed 6 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from new to closed

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 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.