Can I have multiple lists in a Django generic.ListView?

后端 未结 1 1437
时光取名叫无心
时光取名叫无心 2021-02-14 17:45

As a Django beginner I\'m working on the the tutorial provided by django docs at https://docs.djangoproject.com/en/1.5/intro/tutorial04/

In it they demonstrate a list of

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-14 18:20

    Absolutely, you'll just need to write your own 'get_context_data' method that will retrieve those values and then they will be available in the view. Something like:

    def get_context_data(self, *args, **kwargs):
        context = super(IndexView, self).get_context_data(*args, **kwargs)
        context['alphabetical_poll_list'] = Poll.objects.order_by('name')[:5]
        return context 
    

    With this both {{ latest_poll_list }} and {{ alphabetical_poll_list }} would be available in your template.

    0 讨论(0)
提交回复
热议问题