Adding pagination features
Open the api/views.py
file and replace the code for the MessageListResource.get
method with the highlighted lines in the next listing. In addition, make sure that you add the import statement. The code file for the sample is included in the restful_python_chapter_07_01
folder:
from helpers import PaginationHelper
class MessageListResource(Resource):
def get(self):
pagination_helper = PaginationHelper(
request,
query=Message.query,
resource_for_url='api.messagelistresource',
key_name='results',
schema=message_schema)
result = pagination_helper.paginate_query()
return result
The new code for the get
method creates an instance of the previously explained PaginationHelper
class named pagination_helper
with the request
object ...
Get Building RESTful Python Web Services now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.