Flask-sqlalchemy paging. The value returned by the page number generator is None.

when flask queries database confidence with sqlalchemy and displays it in pages

@ops.route("/servers/<int:page>", methods=["GET"])
def servers(page):
    if page is None:
        page = 1
    page_data = ServerInfo.query.order_by(ServerInfo.ExpiredTime).paginate(page=page, per_page=10)
    print(page_data)
    print(page_data.iter_pages())
    for v in page_data.iter_pages():
        print(v)
    return render_template("servers.html", page_data=page_data)

Runtime error. When you look at the background output, you will find

.
<flask_sqlalchemy.Pagination object at 0x0000000007831F60>
<generator object Pagination.iter_pages at 0x000000000780DEB8>
1
2
3
4
5
None
8
9
127.0.0.1 - - [25/Apr/2018 14:30:50] "GET /servers/1 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Python\Python36\lib\site-packages\flask\app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python\Python36\lib\site-packages\flask\app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Python\Python36\lib\site-packages\flask\app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
The value returned by the

page_data.iter_pages () generator contains None

but it"s normal to set per_page to 20 during testing. Why?

Mar.05,2021

in paginate (page=page, per_page=10)
add a error_out=False parameter to try.


this is Pagination. Iter_pages method implementation problem, this method is mainly used to render the paging bar, you can see the source code

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b383d2-2c0e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b383d2-2c0e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?