Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django Basics Final Details url Tag

NoReverseMatch: Error During Template Rendering

I am having trouble figuring out why I am getting this error: NoReverseMatch at / Reverse for 'deets' with arguments '(u'test-post',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['post/(?P<slug>\d+)$']

Template Highlighted Error:

<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>

models function:

    def get_absolute_url(self):
        return reverse('deets', args=[self.slug])


urlpatterns = [
    url(r'(?P<slug>\d+)$', views.post, name='deets'),


urlpatterns = [
    url(r'^$', views.index),
    url(r'^post/', include('blog.urls')),


def post(request, slug):
    post = get_object_or_404(Post, slug=slug)
    return render(request, 'blog/post.html', {'post': post})

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,166 Points

TL;DR: reverse for deets is being passed the string u'test-post' from self.slug. The reverse is looking for digits to match \d+

Perhaps change blog.urls to match word chars and hyphen:

urlpatterns = [
    url(r'(?P<slug>[\w-]+)$', views.post, name='deets'),

Oh, wow... so it was a regex error all along. Thanks!