When I try to load urls described in different parts of urlpatterns, it loads the same view. Obviously, there is an error in urlpatterns I use but I can’t find it.
Here is the first urls.py file:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', home),
url(r'^comments/', include('django.contrib.comments.urls')),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}),
url(r'^episodes/', include('episodes.urls')),
url(r'^news/', news),
url(r'', include('zinnia.urls')),))
And here is urlpatterns in episodes.urls:
urlpatterns = patterns('',
(r'$', seasons_list),
(r'(?P<season>\d{1})/$', episodes_by_season),
(r'(\d{1})/(\d{1})/$', episode),
)
Everytime I try to load url like “/episodes/1” or “/episodes/1/2”, django uses only seasons_list view.
That’s because all URLs have an end-of-string, hence they always match the first pattern. Add beginning anchors to all of them, since included URLconfs only get the part after the match.