I am wondering if it’s necessary to have these two patterns in my urls.py:
url(r'^books/author/(?P<id>\d+)/$', 'books.views.author'),
url(r'^books/author/(?P<id>\d+)/(?P<slug>[-\w]+)/$', 'books.views.author'),
Basically, slug is optional. And view function definition is like this:
def author(request, id, slug=None):
Please advise.
You could wrap the second group and the slash in a non-capturing group and make that whole group optional: