pankaj
pankaj

Reputation: 1346

Django: getting NoReverseMatch at / error

There are a lot of similar issues on SO and i went through most of them, but still unable to resolve my problem.

I am getting the following error:

Reverse for 'category_view' with arguments '()' and keyword arguments '{'pk': 'dynamic-programming'}' not found. 0 pattern(s) tried: [] NoReverseMatch at /articles/

Here is my settings from urls.py file:

url(r'^category/(?P<pk>[\w-]+)/$', views.CategoryDetailView.as_view(), name='category_view')

And, this is my definition of get_absolute_url() from model;

def get_absolute_url(self):
return reverse('category_view', kwargs={'pk': self.slug})

And the caller where I am getting this error is from index.html:

<li><a href="{{ category.get_absolute_url }}">{{ category.name }}</a></li>

I am sure that I am missing something very obvious, but not able to figure it out for past few hours. :(

Content from project's urls.py:

url(r'^articles/$', include('blog.urls', namespace="blog")),
    url(r'^admin/', include(admin.site.urls)),

Upvotes: 0

Views: 592

Answers (1)

catavaran
catavaran

Reputation: 45575

I suspect that you forgot to include the urls.py from your app into the project's urls.py.

UPDATE: if you used the namespace parameter of the include then you have to specify this namespace in the reverse() call:

def get_absolute_url(self):
    return reverse('blog:category_view', kwargs={'pk': self.slug})

Upvotes: 1

Related Questions