简体   繁体   English

当我在基于 class 的视图中应用过滤器时,如何在 django 中使用分页分页。 url 总是不断变化我如何跟踪 url

[英]How do i use pagination pagination in django when i apply filters in class based view. the url always keeps changing how can i track the url

How do I use pagination in Django when I apply filters in a class-based view.当我在基于类的视图中应用过滤器时,如何在 Django 中使用分页。 the URL always keeps changing how can I track the URL to go to the next page. URL 总是不断变化我如何跟踪 URL 到 go 到下一页。 can anyone help me谁能帮我

You can use django rest framework inbuilt pagination classes.您可以使用 django rest 框架内置的分页类。

https://www.django-rest-framework.org/api-guide/pagination/ https://www.django-rest-framework.org/api-guide/pagination/

Personally I use PageNumberPagination .我个人使用PageNumberPagination The result also returns the link of the next and previous pages along with the total count.结果还返回下一页和上一页的链接以及总数。

PageNumberPagination 响应示例

Alternatively, you can use LimitOffsetPagination .或者,您可以使用LimitOffsetPagination This one is more flexible as compared to PageNumberPagination because the offset and limit can be manipulated from the URL.与 PageNumberPagination 相比,这个更灵活,因为可以从 URL 操作偏移量和限制。 This is more suitable to the case when the front end has a feature to change the page size.这更适合前端有改变页面大小的功能的情况。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM