Flask pagination of the data with the paginate

flask with paginate data paging can achieve the effect, first comb of knowledge paginate.

1.paginate usage

the paginate (Page, per_page, error_out = True)
>>> Page Pages
several >>> per_page displayed per page
>>> error_out whether to print an error message

2.paginate property

a) paginate.page Pages
b) paginate.pages Pages
c) paginate.total total number of data
d) paginate.has_prev returns a Boolean value whether there Previous
e) paginate.has_next whether there is a next returns a Boolean value
f) paginate.iter_pages () returns a list of all the page numbers of [1, 2, 3, 4]
g) paginate (page, per_page, error_out) .items returns this page of all the data

Examples

All student information queries, data per page 2, and page through Previous, Next Jump page.

view a)
b) html page parsing data

{% extends 'base_main.html' %}

{% block title %}
    分页显示学生信息
{% endblock %}

{% block content %}
    <h2>学生信息</h2> {% for stu in stus %} 学生编号:{{ stu.s_id }}<br> 学生姓名:{{ stu.s_name }}<br> 学生年龄:{{ stu.s_age }}<br> <br> {% endfor %} 当前页数:{{ paginate.page }} 总页数:{{ paginate.pages }} 一共有{{ paginate.total }}条数据 <br> {% if paginate.has_prev %} <a href="/stu/stupage/?page={{ paginate.prev_num }}">上一页</a> {% endif %} 页码: {% for i in paginate.iter_pages() %} <a href="/stu/stupage/?page={{ i }}">{{ i }}</a> {% endfor %} {% if paginate.has_next %} <a href="/stu/stupage/?page={{ paginate.next_num }}">下一页</a> {% endif %} {% endblock %} 

>>> Note the page a link address, need to pass parameters

 
c) access request

>>> first visit, per page parameters, automatically assigned to page 1, and the current number of pages per page Previous

 Click Next >>> 
 

>>> When the jump to the last page, the link will not be displayed on the next page

 
 

Guess you like

Origin www.cnblogs.com/hzjdpawn/p/12628807.html