1

My django framework is throwing an error while importing 'PaginationSerializer'. Any idea what could have gone wrong? Please find below the line which throws the error. I am using django REST framework 3.1 release.

    from rest_framework.pagination import PaginationSerializer

Below is the error output.

    ImportError at /

    cannot import name 'PaginationSerializer'

    Request Method:     GET
    Request URL:    http://127.0.0.1:3434/
    Django Version:     1.8.2
    Exception Type:     ImportError
    Exception Value:    cannot import name 'PaginationSerializer'
    Exception Location:     /home/djangoDevelopment/test.git/rest_peace/urls.py in <module>, line 9
    Python Executable:  /home/pulak/djangoDevelopment/django-test.git/djenv/bin/python
    Python Version:     3.4.3
valafar
  • 190
  • 1
  • 2
  • 10

2 Answers2

10

PaginationSerializer was removed in DRF 3.1 release. The pagination API underwent a lot of changes, making it both easier to use, and more powerful.

Now, instead of using the PaginationSerializer, you need to override the get_paginated_response() function.

As per the changes announced in DRF 3.1 in Pagination API:

Thepagination_serializer_class view attribute and DEFAULT_PAGINATION_SERIALIZER_CLASS settings key are no longer valid. The pagination API does not use serializers to determine the output format, and you'll need to instead override the get_paginated_response method on a pagination class in order to specify how the output format is controlled.

Rahul Gupta
  • 46,769
  • 10
  • 112
  • 126
1

I think I found what the issue is. Using REST framework v3.1 breaks the pagination. The issue is addressed in the following link. In case someone runs into this kind of trouble in future: Django Rest Framework 3.1 breaks pagination.PaginationSerializer

Community
  • 1
  • 1
valafar
  • 190
  • 1
  • 2
  • 10