view.pyclass PublisherList(DetailView):#通用视图参数model = Publishercontext_object_name = 'publisher_list' #取名字,默认为object_listqueryset = 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 contexturl.pyurlpatterns = 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'这个参数去掉,写错了
2 回答
慕后森
TA贡献1802条经验 获得超5个赞
Generic detail view PublisherList must be called with either an object pk or a slug
通用详细视图出版社列表必须以一个对象主键或者一个slug来调用,你看下url配置吧,还是主要看文档,django好久没碰了
- 2 回答
- 0 关注
- 707 浏览
添加回答
举报
0/150
提交
取消