Paginating records

The paginate() method makes it easy to grab a page or records. paginate() takes two parameters, page_number, and items_per_page.

Attention

Page numbers are 1-based, so the first page of results will be page 1.

  1. >>> for tweet in Tweet.select().order_by(Tweet.id).paginate(2, 10):
  2. ... print(tweet.message)
  3. ...
  4. tweet 10
  5. tweet 11
  6. tweet 12
  7. tweet 13
  8. tweet 14
  9. tweet 15
  10. tweet 16
  11. tweet 17
  12. tweet 18
  13. tweet 19

If you would like more granular control, you can always use limit() and offset().