zoukankan      html  css  js  c++  java
  • DRF get方法返回信息自定义

    class MyPagination(PageNumberPagination):
        page_size = 10
        page_size_query_param = "page_size"
        max_page_size = 100
    
        def get_paginated_response(self, data):
            return Response(OrderedDict([
    
                ('count', self.page.paginator.count),
                ('next', self.get_next_link()),
                ('previous', self.get_previous_link()),
                ('results', data)
            ]))
    
    这种方法是设置全局的,如果想要个性化设置可以使用继承
    from rest_framework.pagination import PageNumberPagination
    from collections import OrderedDict
    from rest_framework.response import Response
    
    
    class MyPagination(PageNumberPagination):
        page_size = 10
        page_size_query_param = "page_size"
        max_page_size = 100
    
    
    class MyPaginationSpecial(MyPagination):
        def get_paginated_response(self, data):
            return Response(OrderedDict([
    
                ('count', self.page.paginator.count),
                ('next', self.get_next_link()),
                ('previous', self.get_previous_link()),
                ('results', data)
            ]))
  • 相关阅读:
    优化eclipse
    Servlet与jsp间的传值问题
    servlet & javabean
    Java数据类型
    CentOS 7 安装tomcat
    Nginx配置详解
    PHP文件缓存实现
    lnmp编译安装
    Php安全规范
    php编码规范
  • 原文地址:https://www.cnblogs.com/liangliangzz/p/12706276.html
Copyright © 2011-2022 走看看