class PublisherDetail(DetailView):model = Publisherdef get_context_data(self, **kwargs): context = super(PublisherDetail, self).get_context_data(**kwargs) context['book_list'] = Book.objects.all() #????return context麻煩解釋一下#?那行是什么意思?context應(yīng)該是一個(gè)對(duì)象集吧?context[ ]怎么好像把它當(dāng)成字典來(lái)用啊?本來(lái)在沒(méi)有重寫(xiě)get_context_data函數(shù)的時(shí)候,我在模板里面可以這樣:{% for publisher in object_list %}<li>{{ publisher.name }}</li>{% endfor %}但是現(xiàn)在不行了吧,那要怎么使用context['book_list'] = Book.objects.all()這個(gè)數(shù)據(jù)呢?!
Django view問(wèn)題
月關(guān)寶盒
2018-07-15 15:17:23