NoReverseMatch question

158 views
Skip to first unread message

goblue0311

unread,
Nov 21, 2008, 9:16:37 AM11/21/08
to Django users
Hi all:

I'm receiving this error:

#*************************************
NoReverseMatch at /blog/
Reverse for 'blog_detail' with arguments '()' and keyword arguments
'{'year': 2008, 'slug': u'second_post', 'day': 21, 'month': 'nov'}'
not found."
#*************************************

when I try to call this function from views.py:

#*************************************
def post_list(request, page=0):
queryset = Post.objects.published()

for item in queryset:
print item.get_absolute_url()

return list_detail.object_list(
request,
queryset,
paginate_by = 20,
page = page,
)
#*************************************

with this urls.py:

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

This may be an odd thing to do, but I'm trying to debug an issue where
my blog_index view doesn't let me see the detailed view for any of the
blog entries. In any case, I think my URLconf and model definition of
get_absolute_url( ) are aligned, but maybe that's not the case.

Suggestions?

Thanks!

goblue0311

unread,
Nov 21, 2008, 9:22:50 AM11/21/08
to Django users
Another note if interest is that the error message is citing the
keyword arguments in the order year, slug, day, and month. However,
get_absoloute_url and the urls.py function use year, month, day, and
slug. Maybe I have some outdated code here, but where would it reside?

Alex Koshelev

unread,
Nov 21, 2008, 9:24:40 AM11/21/08
to django...@googlegroups.com
You have an underscore in slug - "second_post" but your regex doesn't allow it - "[-\w]+". I think it is the problem.
And why you did you choose "\w" for day?

Jarek Zgoda

unread,
Nov 21, 2008, 9:35:29 AM11/21/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-11-21, o godz. 15:22, przez goblue0311:

Python doctionaries do not have any notion of "ordering".

--
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
jarek...@redefine.pl

goblue0311

unread,
Nov 21, 2008, 9:40:10 AM11/21/08
to Django users
Thanks for the suggestion!

This code came from the basicApps collection, so I'm not sure why
they're using a Word regex to match the day, I'm going to try changing
that to Digit.

However, I did remove the underscore from my slug, so now it's just
'secondPost', and I get the same error. I also tried deleting all the
*.pyc files, because I'm a little concerned about the re-ordering of
the error message, although maybe that's nothing.


On Nov 21, 9:24 am, "Alex Koshelev" <daeva...@gmail.com> wrote:
> You have an underscore in slug - "second_post" but your regex doesn't allow
> it - "[-\w]+". I think it is the problem.
> And why you did you choose "\w" for day?
>

goblue0311

unread,
Nov 21, 2008, 9:47:12 AM11/21/08
to Django users
good call - I repeated my concern below before I saw your response, so
please disregard.
> jarek.zg...@redefine.pl

Jarek Zgoda

unread,
Nov 21, 2008, 10:15:57 AM11/21/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-11-21, o godz. 15:40, przez goblue0311:

> Thanks for the suggestion!
>
> This code came from the basicApps collection, so I'm not sure why
> they're using a Word regex to match the day, I'm going to try changing
> that to Digit.
>
> However, I did remove the underscore from my slug, so now it's just
> 'secondPost', and I get the same error. I also tried deleting all the
> *.pyc files, because I'm a little concerned about the re-ordering of
> the error message, although maybe that's nothing.


The NoReverseMatch will also pop up if the view function you declared
to handle the url is not importable.

--
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
jarek...@redefine.pl

goblue0311

unread,
Nov 21, 2008, 1:16:03 PM11/21/08
to Django users
ok, the view function I'm using appears to be importable - because if
I remove the line "print item.get_absolute_url()", the view function
is called appropriately, with the odd exception that all instances
where the template is calling "get_absolute_url( )" are resolving to
the same page.

A clue may be that in the application urls.py file, when I replace
"view=blog_views.post_list" with "view=basicBlog.blog.views.post_list"
it claims to not be able to find "basicBlog"

Here's the complete code, I'm quite stuck on this and appreciate your
help:

urls.py from project root
#*************************************************
from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
(r'^$', include('basicBlog.blog.urls')),
(r'^blog/', include('basicBlog.blog.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
(r'^admin/(.*)', admin.site.root),
)
#*************************************************

urls.py from blog application
#*************************************************
from django.conf.urls.defaults import *
from basicBlog.blog import views as blog_views

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

url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$',
view=blog_views.post_archive_day,
name='blog_archive_day'),

url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$',
view=blog_views.post_archive_month,
name='blog_archive_month'),

url(r'^(?P<year>\d{4})/$',
view=blog_views.post_archive_year,
name='blog_archive_year'),

url(r'^categories/(?P<slug>[-\w]+)/$',
view=blog_views.category_detail,
name='blog_category_detail'),

url (r'^categories/$',
view=blog_views.category_list,
name='blog_category_list'),

url (r'^search/$',
view=blog_views.search,
name='blog_search'),

url(r'^page/(?P<page>\w)/$',
view=blog_views.post_list,
name='blog_index_paginated'),

url(r'^$',
view=blog_views.post_list,
name='blog_index'),
)
#*************************************************

and views.py for the post_list view:
#*************************************************
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
from django.views.generic import date_based, list_detail
from basicBlog.blog.models import *

import datetime
import re

def post_list(request, page=0):
queryset = Post.objects.published()

for item in queryset:
print item.get_absolute_url()

return list_detail.object_list(
request,
queryset,
paginate_by = 20,
page = page,
)
post_list.__doc__ = list_detail.object_list.__doc__

# this file goes on...

#*************************************************
Reply all
Reply to author
Forward
0 new messages