django通用视图

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'这个参数去掉,写错了

蝴蝶刀刀
浏览 708回答 2
2回答

慕后森

Generic detail view PublisherList must be called with either an object pk or a slug通用详细视图出版社列表必须以一个对象主键或者一个slug来调用,你看下url配置吧,还是主要看文档,django好久没碰了
打开App,查看更多内容
随时随地看视频慕课网APP