首页 > 解决方案 > 分页不适用于过滤 Django

问题描述

我有一个Listview与分页完美配合的,它看起来像:

class BranchListView(ListView):
    model = Branch
    paginate_by = 10

现在我需要将其更改为Filterview并使用django_filters,我正在尝试以FilterView这种方式创建分页

class BranchListView(FilterView):
    model = Branch
    paginate_by = 10
    filter_class = BranchFilter
    template_name = 'erp_system/branch_list.html'
    filterset_fields = ['id', 'name']

这就是我在模板中使用分页部分的方式

{% if is_paginated %}
    <div class="pagination">
        <span class="page-links">
            {% if page_obj.has_previous %}
                <a href="?page={{ page_obj.previous_page_number }}"><button
                        class="btn-success">الصفحة السابقة</button> </a>
            {% endif %}
            <span class="page-current">
                 صفحة رقم  {{ page_obj.number }} من {{ page_obj.paginator.num_pages }}.
            </span>
            {% if page_obj.has_next %}
                <a href="?page={{ page_obj.next_page_number }}"><button class="btn-success">الصفحة التالية</button> </a>
            {% endif %}
        </span>
    </div>
{% endif %}

现在过滤工作正常。但是根本没有分页。

标签: djangopaginationfilteringdjango-filter

解决方案


推荐阅读