如何在Django中为同一页面创建两个分页?

时间:2018-07-27 14:21:55

标签: django listview pagination

我已经在互联网上进行搜索,但是找不到一个好的答案,我想知道是否可以使用ListView创建多个分页,例如我更改了上下文以返回两个不同对象的列表,然后将每一行,每一行都有该列表的页码。 我应该如何实现呢?

ListView

class IndexView(TemplateView):
    template_name = "index.html"

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        context['oportunities_idea'] = Oportunity.objects.filter(goal_oportunity_idea=True)
        context['oportunities_project'] = Oportunity.objects.filter(goal_oportunity_project=True)
        return context

index.html

<div class="row mt15"><!--project-->
    <div id="home" class="tab-pane row fade in active">   
        <legend>Projects</legend>                                                     
            {% for project in  oportunities_project %}                    
                <h2>{{project.title}}<h2>                    
                    {% if forloop.counter|divisibleby:1 %}
                            </li>
                            <li>
                    {% endif %}
            {% endfor %}
    </div>     
 </div>
<div class="row mt15">
    <div id="home" class="tab-pane row fade in active">   
        <legend>Ideas</legend>                                                     
            {% for idea in  oportunities_idea %}                    
                <h2>{{idea.title}}<h2>                   
                    {% if forloop.counter|divisibleby:1 %}
                            </li>
                            <li>
                    {% endif %}
            {% endfor %}
    </div>     
 </div>

0 个答案:

没有答案
相关问题