在 django rest 框架中应用自定义分页后分页链接显示为空

问题描述

我使用了 Django 休息框架中提到的自定义分页。在那,我不得不使用我的项目名称来提供CustomPagination的路径,但每次都说找不到模块。

然后我在视图中手动导入分页文件。它确实有效,但我的分页链接显示为空。我已经把图片在这里了。

enter image description here

我的观点:

from .pagination import CustomPagination

class ProductAPIView(ListAPIView):
    permission_classes = [AllowAny]
    queryset = Product.objects.all()
    serializer_class = ProductSerializer    
    filterset_class = ProductFilter
    pagination_class = CustomPagination

我的 pagination.py 文件

class CustomPagination(PageNumberPagination):
    def get_paginated_response(self,data):
        return Response({
            'links': {
                'next': self.get_next_link(),'prevIoUs': self.get_prevIoUs_link()
            },'count': self.page.paginator.count,'results': data
        })

我的设置文件

 # 'DEFAULT_PAGINATION_CLASS': 'RupSEOnline.core.pagination.CustomPagination','PAGE_SIZE': 100,

我已注释掉分页类并在视图中手动导入它,因为它说找不到模块。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...