2015-07-19 75 views
1

我的django框架在導入'PaginationSerializer'時拋出錯誤。任何想法可能會出錯?請在下面找到引發錯誤的行。我正在使用django REST框架3.1版本。django REST框架錯誤:無法導入名稱'PaginationSerializer'

from rest_framework.pagination import PaginationSerializer 

以下是錯誤輸出。

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 
+0

你加'rest_framework'到'INSTALLED_APPS'在設置 –

+0

是的,當然。其他進口例如路由器,串行器工作正常! – valafar

+0

你使用的是哪個版本? –

回答

8

PaginationSerializer在DRF 3.1版本中被刪除。分頁API進行了很多更改,使其更易於使用,功能更強大。

現在,您不需要使用PaginationSerializer,而需要覆蓋get_paginated_response()函數。

按在DRF 3.1 Pagination API公佈的changes

The pagination_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.

相關問題