我想在模板index.html
中顯示以下兩個視圖。如何在Django模板中顯示多個視圖?
class IndexView(generic.ListView):
template_name = 'items/index.html'
context_object_name = 'popular_items_list'
def get_queryset(self):
return Item.objects.order_by('-rating')[:5]
class tryView(generic.ListView):
template_name = 'items/index.html'
context_object_name = 'latest_items_list'
def get_queryset(self):
return Item.objects.order_by('pub_date')[:5]
有沒有辦法將這兩個視圖組合成一個視圖?
我該如何獲得index.html
上顯示的兩個查詢集?
是否可以發送模板中的所有Item.objects.all()
和過濾器?
非常感謝。 – b3ast 2014-09-30 17:32:57