Skip to content
Advertisement

Django rest framework override page_size in ViewSet

I am having problem with django rest framework pagination. I have set pagination in settings like –

JavaScript

Below is my viewset.

JavaScript

I want to set different page size for this viewset. I have tried setting page_size and Paginate_by class variables but list is paginated according to PAGE_SIZE defined in settings. Any idea where I am wrong ?

Advertisement

Answer

I fixed this by creating custom pagination class. and setting desired pagesize in class. I have used this class as pagination_class in my viewset.

JavaScript

I am not sure if there is any easier way for this. this one worked for me. But I think its not good to create new class just to change page_size.

Edit – simple solution is set it like

JavaScript

in ViewSet.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement