2017-06-13 45 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

相关问题