pythonregexdjangourlconf

Django Url NoReverseMatch


I'm trying to create an url that has both the slug and the pk of a given model. However, I'm running into the NoReverseMatch error when I try this.

The url:

urlpatterns = patterns('',
    # Blah Blah
    url(r'^dashboard/(?P<slug>[-\w]+])-by-(?P<pk>\d+)/$', WebsiteTemplateView.as_view(), name="websitedetail"),
)

Error:

NoReverseMatch: Reverse for 'websitedetail' with arguments '()' and keyword arguments '{'pk': 42, 'slug': u'when-you-talk-you-hardly-even-look-in-my-eyes'}' not found. 1 pattern(s) tried: ['dashboard/(?P<slug>[-\\w]+])-by-(?P<pk>\\d+)/$']

Thanks in advance.


Solution

  • Remove the excess square bracket in the <slug> named group:

    url(r'^dashboard/(?P<slug>[-\w]+)-by-(?P<pk>\d+)/$',
                             WebsiteTemplateView.as_view(), name="websitedetail"),