對分布及每頁數目進行設置
在settting.py中添加
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS':[
'rest_framework.Pagination.PageNumberPaginaion',
'PAGE_SIZE':100,
#注:每頁數目不可修改
],
}
from rest_framework.Pagination import PageNumberPagination
class 分頁類名(PageNumberPagination):
page_size = 10 #默認是10條
page_query_param = 'page'
page_size_query_param = 'size'
max_page_size = 100 #最多可以設置100條
from .pagination import 分頁類名
# Create your views here.
class 庫名ViewSet(ModelViewSet):
...
pagination_class = 分頁類名
http://localhost:8000/api/students/?page=nu&size=nu