Opened 15 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

Description

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.

urls.py:
    (r'^blog/', include('kulleen.blog.urls.blogs')),
    (r'^(?P<member>[\w]+)/blog/', include('kulleen.blog.urls.blogs')),

blog/urls/blogs.py:
    url(
        r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$',
        'object_detail',
        dict(
            blog_dict,
            slug_field='slug',
            template_object_name = 'entry',
        ),
        name='entry_view',
    ),


exception:
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
     57

/usr/lib64/python2.5/site-packages/django/db/models/base.pyc in get_absolute_url(opts, func, self, *args, **kwargs)
    509
    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)
    512
    513

/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)))
    253
    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))
    242
    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, 15 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, 15 years ago

Cc: flavio.curella@… added

comment:3 by Flavio Curella, 15 years ago

this is my test case with django r9699

blog/models.py:

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'))

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

urls.py:

from django.conf.urls.defaults import *

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

blog/urls.py:

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

urlpatterns = patterns('',
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
        view=blog_views.post_detail,
        name='blog_detail'),
)

./manage.py 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/functional.py", line 55, in _curried
    return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
  File "/Library/Python/2.5/site-packages/django/db/models/base.py", 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/__init__.py", line 30, in inner
    return reverse(bits[0], None, *bits[1:3])
  File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py", line 254, in reverse
    *args, **kwargs)))
  File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py", 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, 15 years ago

Cc: flavio.curella@… removed

comment:5 by Flavio Curella, 15 years ago

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

comment:6 by Ivan Giuliani, 15 years ago

Resolution: invalid
Status: newclosed

in reply to:  6 ; comment:7 by Karen Tracey, 15 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, 15 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, 15 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 urls.py file. That pattern is capturing everything after the string "/blog/" (the (.*) part) and leaving nothing for the patterns in blog/urls.py to match against. Changing the urls.py pattern line to

#python
(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