view.py
class PublisherList(DetailView):
#通用视图参数
model = Publisher
context_object_name = 'publisher_list' #取名字,默认为object_list
queryset = Publisher.objects.all()
slug_field = 'publisher_list_slug'
template_name = 'helloTime.html'
def get_context_data(self,**kwargs): #重写DetailView类的方法
context = super(PublisherList,self).get_context_data(**kwargs)
context['book_list'] = Book.objects.filter(firstname__contains='jobs')
return context
url.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'myTest2.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
(r'^admin/', include(admin.site.urls)),
#url(r'^hello/', 'myTest2.views.caluteTime'),
#url(r'^search/$','search')
(r'^hello/$', PublisherList.as_view()),
)
slug_field = 'publisher_list_slug'这个参数去掉,写错了
慕后森