2017-06-13 44 views
0

我試圖在名爲blogpage的模板中使用兩個視圖列表(post_list和classification_list)。這是我已經做了解決問題,但它沒有工作:如何在一個模板中合併x視圖

class GenViewList(ListView): 
    model = Posting,Classification 
    template_name = 'Blog/blogpage.html' 

    def get_context_data(self, **kwargs): 
     context=super(BlogViewList,self).get_context_data(**kwargs) 
     context['latest_post_list']=Posting.objects.filter().order_by('-id')[:30] 
     context['classification_list']=Classification.objects.all().order_by('id') 
     return context 

任何幫助將不勝感激!

回答

0

你可以只讓一個TemplateView

from django.views.generic import TemplateView 

class GenViewList(TemplateView): 
    template_name = 'Blog/blogpage.html' 

    def get_context_data(self, **kwargs): 
     context=super(BlogViewList,self).get_context_data(**kwargs) 
     context['latest_post_list']=Posting.objects.filter().order_by('-id')[:30] 
     context['classification_list']=Classification.objects.all().order_by('id') 
     return context 
+0

非常感謝,它的工作 –

0

的ListView不與2種不同的型號。你可以提供你的get_queryset,但在你構建你的方式get_context似乎你需要一些不同的東西像TemplateView

相關問題