url patterns are checked in the order they are defined
so that:
urlpatterns = [ url(r'(?P<post_id>[^/]+)', GenreDetail.as_view(), name = 'post'), url(r'(?P<post_id>[^/]+)/(?P<slug>[-\w]+)$', GenreDetail.as_view()), ]
... the first pattern gets matched (because it doesn't end with $ , so the extra segment is simply ignored)
... and this template passes only one arg keyword
This is generally a bad idea to have multiple URL patterns pointing to the same look. If possible, you should try to create one regular expression (for example, using optional groups ) that handles various cases of URLs for a particular kind. This is more explicit.
On the other hand, simply reordering your templates to give a more explicit first will also work and be correct (this is the Django rule for URLs!)
urlpatterns = [ url(r'(?P<post_id>[^/]+)/(?P<slug>[-\w]+)$', GenreDetail.as_view()), url(r'(?P<post_id>[^/]+)', GenreDetail.as_view(), name = 'post'), ]
Since @ozgur mentions that you also need to tell the view to use post_id instead of pk by setting pk_url_kwarg
Anentropic
source share