当我尝试加载在 urlpatterns 的不同部分中描述的 url 时,它会加载相同的视图。显然,我使用的 urlpatterns 有错误,但我找不到。
这是第一个 urls.py 文件:
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')),))
这是 episodes.urls 中的 urlpatterns:
urlpatterns = patterns('',
(r'$', seasons_list),
(r'(?P<season>\d{1})/$', episodes_by_season),
(r'(\d{1})/(\d{1})/$', episode),
)
每次我尝试加载像“/episodes/1”或“/episodes/1/2”这样的网址时,django 只使用 seasons_list 视图。