# 普通分頁(yè)
from rest_framework.pagination import PageNumberPagination
# from rest_framework.versioning import URLPathVersioning
# class Book(ViewSetMixin, APIView):
#版本控制局部使用
# versioning_class = URLPathVersioning
# def get_all(self, request,*args,**kwargs):
# 提供給咱的解析
# url2=request.versioning_scheme.reverse('ttt',request=request)
# print(url2)#獲取到帶有版本號(hào)的ip地址
# response = {'status': 100, 'msg': '查詢成功'}
# book_list = models.Book.objects.all()
# # 實(shí)例化產(chǎn)生一個(gè)分頁(yè)對(duì)象
# # 不繼承來(lái)修改對(duì)象的值
# page=PageNumberPagination()
# # 每頁(yè)顯示多少條
# page_size = 3
# # 查詢的key,問(wèn)號(hào)后面的key
# page_query_param = 'aa'
# # 指定當(dāng)前頁(yè)顯示多少條
# page_size_query_param='size'
# # 每頁(yè)最多顯示多少條
# max_page_size=4
# # 第一個(gè)參數(shù):要分頁(yè)的數(shù)據(jù),第二個(gè)參數(shù)request對(duì)象,第三個(gè)參數(shù),當(dāng)前視圖對(duì)象
# page_list = page.paginate_queryset(book_list, request, self)
# # 再序列化的時(shí)候,用分頁(yè)之后的數(shù)據(jù)
# ser = mySer.BookSerializer(instance=page_list, many=True)
# # response['data'] = ser.data
# # return Response(response)
# # 會(huì)帶著鏈接,和總共的條數(shù)(不建議用)
# return page.get_paginated_response(ser.data)
# # return Response(ser.data)
路由----------------------------------------------------------------------------------------------------
#版本控制路由
# url(r'^(?P[v1|v2|v3]+)/books/$', views.Book.as_view({'get': 'get_all'}), name='ttt'),
在setting中---------------------------------------------------------------------------------------------
REST_FRAMEWORK = {
# 'DEFAULT_VERSIONING_CLASS':'rest_framework.versioning.URLPathVersioning',#版本控制全局使用
# 'VERSION_PARAM': 'version',
# 'DEFAULT_VERSION': 'v1',
# 'ALLOWED_VERSIONS': ['v1', 'v2'],
}
網(wǎng)頁(yè)名稱:rest_framework分頁(yè),版本控制
新聞來(lái)源:
http://weahome.cn/article/ipcpdg.html