urls.py from . import views ... url(r'^$', views.IndexView.as_view, name="index"), url(r'^(?P<pk>d+)$', views.DetailView.as_view(), name="detail"), #DetailView会从url中捕获pk的值,一定要是pk!
views.py from django.views import generic from .models import Album class IndexView(generic.ListView): template_name = 'music/index.html' #默认值: <app name>/<model name>_list.html 这里 music/album_list.html context_object_name = 'album_list' #默认值: object_list def get_queryset(): return Album.objects.all() class DetailView(generic.DetailView); model = Album template_name = 'music/detail.html' #默认值:<app name>/<model name>_detail.html 这里 music/album_detail.html