view.pyclass PublisherList(DetailView):#通用視圖參數(shù)model = Publishercontext_object_name = 'publisher_list' #取名字,默認(rèn)為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'這個參數(shù)去掉,寫錯了
2 回答

慕后森
TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
Generic detail view PublisherList must be called with either an object pk or a slug
通用詳細(xì)視圖出版社列表必須以一個對象主鍵或者一個slug來調(diào)用,你看下url配置吧,還是主要看文檔,django好久沒碰了
- 2 回答
- 0 關(guān)注
- 743 瀏覽
添加回答
舉報
0/150
提交
取消