Opened 16 years ago

Closed 15 years ago

#9496 closed (worksforme)

reverse() function doesn't seem to take account of the includer urlconf

Reported by: Seemant Kulleen Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a urlconf being included from the top-level urlconf. the one being included is named, and I'm trying to get the reverse() function to work with the named one. It fails with the posted exception. I think this is wrong behaviour. Forgive my unorthodox use if this is the correct behaviour.
    (r'^blog/', include('')),
    (r'^(?P<member>[\w]+)/blog/', include('')),

            template_object_name = 'entry',

In [1]: from blog.models import Entry

In [2]: e = Entry.objects.all()[65]

In [3]: e.get_absolute_url()
NoReverseMatch                            Traceback (most recent call last)

/home/seemant/Projects/websites/kulleen/<ipython console> in <module>()

/usr/lib64/python2.5/site-packages/django/utils/functional.pyc in _curried(*moreargs, **morekwargs)
     53 def curry(_curried_func, *args, **kwargs):
     54     def _curried(*moreargs, **morekwargs):
---> 55         return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
     56     return _curried

/usr/lib64/python2.5/site-packages/django/db/models/base.pyc in get_absolute_url(opts, func, self, *args, **kwargs)
    510 def get_absolute_url(opts, func, self, *args, **kwargs):
--> 511     return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs)

/home/seemant/Projects/websites/kulleen/blog/models.pyc in get_absolute_url(self)
     49                 'month': self.pub_date.strftime('%b').lower(),
     50                 'day': self.pub_date.strftime('%d'),
---> 51                 'slug': self.slug
     52             }
     53         )

/usr/lib64/python2.5/site-packages/django/core/urlresolvers.pyc in reverse(viewname, urlconf, args, kwargs, prefix)
    250         prefix = get_script_prefix()
    251     return iri_to_uri(u'%s%s' % (prefix, get_resolver(urlconf).reverse(viewname,
--> 252             *args, **kwargs)))
    254 def clear_url_caches():

/usr/lib64/python2.5/site-packages/django/core/urlresolvers.pyc in reverse(self, lookup_view, *args, **kwargs)
    239                 return candidate
    240         raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
--> 241                 "arguments '%s' not found." % (lookup_view, args, kwargs))
    243 def resolve(path, urlconf=None):

NoReverseMatch: Reverse for 'entry_view' with arguments '()' and keyword arguments '{'member': u'seemant', 'year': 2006, 'slug': u'the-master-cleanse-day-2', 'day': '03', 'month': 'dec'}' not found.

Change History (12)

comment:1 by Malcolm Tredinnick, 16 years ago

Try as I might, I cannot reproduce this problem. If you could construct a very small, self-contained example that reliably demonstrates the problem, that might make things easier to debug. I can't see how this could be happening and all the tests I create to replicate it, including making a small project with a similar structure to yours, pass.

comment:2 by Flavio Curella, 16 years ago

Cc: flavio.curella@… added

comment:3 by Flavio Curella, 16 years ago

this is my test case with django r9699


class Post(models.Model):
    """Post model."""
    title           = models.CharField(_('title'), max_length=200)
    slug            = models.SlugField(_('slug'), unique_for_date='publish')
    publish         = models.DateTimeField(_('publish'))

    def get_absolute_url(self):
        return ('blog_detail', None, {
            'year': self.publish.year,
            'month': self.publish.strftime('%b').lower(),
            'slug': self.slug

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^blog/(.*)', include('')),


from django.conf.urls.defaults import *
from blog import views as blog_views

urlpatterns = patterns('',

./ shell:

>>> from blog.models import Post
>>> Post.objects.all()
[<Post: Donec non tortor in arcu mollis feugiat>, <Post: title>]
>>> p = Post.objects.all()[0]
>>> p
<Post: Donec non tortor in arcu mollis feugiat>
>>> p.get_asbolute_url()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Post' object has no attribute 'get_asbolute_url'
>>> p.get_absolute_url()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/utils/", line 55, in _curried
    return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
  File "/Library/Python/2.5/site-packages/django/db/models/", line 532, in get_absolute_url
    return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs)
  File "/Library/Python/2.5/site-packages/django/db/models/", line 30, in inner
    return reverse(bits[0], None, *bits[1:3])
  File "/Library/Python/2.5/site-packages/django/core/", line 254, in reverse
    *args, **kwargs)))
  File "/Library/Python/2.5/site-packages/django/core/", line 243, in reverse
    "arguments '%s' not found." % (lookup_view, args, kwargs))
NoReverseMatch: Reverse for 'blog_detail' with arguments '()' and keyword arguments '{'year': 2008, 'slug': u'donec-non-tortor', 'day': 29, 'month': 'nov'}' not found.

comment:4 by anonymous, 16 years ago

Cc: flavio.curella@… removed

comment:5 by Flavio Curella, 16 years ago

sorry, I just found the error was mine. I apologize for the noise.

comment:6 by Ivan Giuliani, 16 years ago

Resolution: invalid
Status: newclosed

in reply to:  6 ; comment:7 by Karen Tracey, 16 years ago

Replying to kratorius:
What's the reason for closing this as invalid? The person (gogna) who said "sorry, I just found the error was mine. I apologize for the noise" is not the same as person who originally opened the ticket (seemant). I do wish gonga had said what, exactly, the error was, perhaps it is the same problem as the original poster, but I'm not sure that's 100% obvious from what we have here.

in reply to:  7 comment:8 by Ivan Giuliani, 16 years ago

Resolution: invalid
Status: closedreopened

Replying to kmtracey: woops, sorry for closing this, I just made confusion with names.

comment:9 by Seemant Kulleen, 16 years ago

For some reason, I don't get emailed on updates, so I didn't see the comments till just now. I'm so sorry for the latency. I will put my examples up here in just a few minutes

comment:10 by Jacob, 15 years ago

Triage Stage: UnreviewedAccepted

comment:11 by Malcolm Tredinnick, 15 years ago

The error in gogna's example in comment:3 is in the file. That pattern is capturing everything after the string "/blog/" (the (.*) part) and leaving nothing for the patterns in blog/ to match against. Changing the pattern line to

(r'^blog/', include('blog.urls')),

fixes that problem.

So I'm still in the position of not being able to repeat this problem. Unless somebody comes up with a reliable failing case in the next few weeks, I think we're going to have to close this as invalid. I've created a lot of different variations on the original problem report and none of them have failed.

comment:12 by Jacob, 15 years ago

Resolution: worksforme
Status: reopenedclosed
Note: See TracTickets for help on using tickets.
Back to Top