# How to use pagination with tryton\_flask

**URL:** https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957
**Category:** Developer
**Tags:** flask
**Created:** [July 1, 2020, 5:04pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957 "2020-07-01T17:04:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 1, 2020, 5:04pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957/1 "2020-07-01T17:04:38Z")

</div>

Hi,

I’m working in a blog with tryton\_flask and tryton. I want to add a pagination option to the main page but I don’t know how to do the query with FROM and TO arguments.

I’m using the follow code to get the records. Now I want to get 1-24, 25-49 range of records.

`entries = Entry.search([('published','=',True)])`

Thanks in advance.

---

<div class="post-metadata">

### Author: ![lukio](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lukio/32/98_2.png) [@lukio](https://discuss.tryton.org/u/lukio)
#### Post date: [July 1, 2020, 6:07pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957/2 "2020-07-01T18:07:03Z")

</div>

Hi! I believe that you can pass _offset_, _limit_, _order_ and _count_ parameters to _search_ method. Check the doc of [search method](https://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.ModelStorage.search)

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [July 1, 2020, 8:42pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957/3 "2020-07-01T20:42:19Z")

</div>

There is flask extensions to manage pagination called [flask-paginate](https://pypi.org/project/flask-paginate/), which can be used with flask-tryton.

Here is some example:

```python

from flask_paginate import Pagination, get_page_args 

@app.route('index')
def index(self):
    page, per_page, offset = get_page_args()                               
    domain = []                                                              
    records = Model.search(domain, order=[('date', 'DESC'), ('id', 'DESC')],  
        offset=offset, limit=per_page)                                     
    count = Model.search(domain, count=True)                                
    pagination = Pagination(                                               
            page=page, total=count, search=False)
    return render_template(                                                
        'template.html', records=records, pagination=pagination)

```

Hope it helps!

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 2, 2020, 3:21pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957/4 "2020-07-02T15:21:37Z")

</div>

It works like a charm!

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [August 1, 2020, 3:21pm UTC](https://discuss.tryton.org/t/how-to-use-pagination-with-tryton-flask/2957/5 "2020-08-01T15:21:44Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
