使用Django Pagination時,有任何方法可以在http請求中指定page_size嗎?我想在請求中沒有發送時使用默認的page_size。在http請求(Django)中發送page_size
在我settings.py
,我有:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
'DEFAULT_METADATA_CLASS': 'myApp.views.MyAppMetadata',
'PAGINATE_BY': 20,
'USE_ABSOLUTE_URLS': True,
'DEFAULT_FILTER_BACKENDS': (
'rest_framework.filters.DjangoObjectPermissionsFilter',
'rest_framework.filters.DjangoFilterBackend',
'rest_framework.filters.OrderingFilter'
),
'DEFAULT_PAGINATION_CLASS': 'myApp.paginators.pagination.CustomPagination',
}
這是我的分頁類:
class CustomPagination(PageNumberPagination):
def get_paginated_response(self, data):
return Response(OrderedDict([
('count', self.page.paginator.count),
('next', self.get_next_link()),
('previous', self.get_previous_link()),
('current_page', self.page.number),
('total_pages', self.page.paginator.num_pages),
('results', data)
]))
應如何page_size_query_param
參數進行設置?