views:

35

answers:

2

Hey guys,

Maybe i am missing something, but according to the django docs (1.2), i have setup my URLS, models exactly as specified to ensure i am not hard-coding urls returned for get_absolute_url.

Here's what i have:

in urls.py

urlpatterns = patterns('django.views.generic.list_detail',
    url(r'^$','object_list',
            { 'queryset': product.objects.all(),
            'template_name': 'products/list.html',
            },
            name='product_list'),  
    url(r'^(?P<slug>[-\w]+)/$','object_detail',
            { 'queryset': product.objects.all(),
            'template_name': 'products/detail.html',
            },
            name='product_detail'), 
)

in models.py

@models.permalink
def get_absolute_url(self):
    return ('product_detail', (), {'slug': str(self.slug)})

The method returns an empty string in the templates, and from the shell it gives an error.

NoReverseMatch: Reverse for 'product_detail' with arguments '()' and keyword arguments '{'slug': 'dd-d--'}' not found.

This should resolve should it not, since urls.py has a name : product_detail

+1  A: 

Try changing this line:

url(r'(?P<slug>[-\w]+)/^$','object_detail',

to

url(r'^(?P<slug>[-\w]+)/$','object_detail',

Carret (^) stands for beginning of the line, so it is illogical in the context you wrote it since it means the line has content before it even begins.

rebus
nicely picked up, made the change. However it seems it still cannot reverse the url.
izzy
I've tested the pattern and as far as i can tell it works ok, apart from that i can't find anything else missing.
rebus
+2  A: 

Syntax seems to be correct, are you sure your urls.py gets included? Try stepping in debuggin in view code and use reverse function first to generate the url.

My blind guess would be, something is wrong with your urls.py file in general.

iElectric
yea, figured it out last night. Was not including it correctly in root urls.
izzy
Then why is my answer not correct:P
iElectric