Skip to Content
Building RESTful Python Web Services
book

Building RESTful Python Web Services

by Gastón C. Hillar
October 2016
Intermediate to advanced
418 pages
9h 52m
English
Packt Publishing
Content preview from Building RESTful Python Web Services

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On RESTful Python Web Services - Second Edition

Hands-On RESTful Python Web Services - Second Edition

Gastón C. Hillar

Publisher Resources

ISBN: 9781786462251Supplemental Content