The flask finisher

paginate (): paging query returns a page objects

the paginate (parameter 1, parameter 2, parameter 3):

  Parameter 1: Current is the first few pages (page)

  Parameter 2: Showing several messages (per_page)

  Parameter 3: error_out: error_out = False under circumstances not throw

      If error_out = True then the following situations throws Exception 404: Item not found, and the page is not less than a page, or a page or per_page per_page negative integer not greater than the total page number of pages;

app.route @ ( '/ booklist /', Methods = [ 'the GET', 'the POST']) 
DEF book_list ():
Page = int (request.args.get ( 'Page',. 1)) # current page, request.args.get () method to get the parameters of the page, if you do not get to page defaults to 1
per_page = 3 # page number
paginate = Book.query.paginate (page, per_page, error_out = False) # create page object
return render_template ( 'book_list_paginate.html', paginate = paginate)

attributes:
items: representation obtained results
pages: represents a total of how many pages
page: get the current number of pages
total: total item number data
has_prev: is there a Previous
has_next: is there a next
prev_num: Previous page
next_num: Next page
iter_page (): current page list of page


<! DOCTYPE HTML> 
<HTML lang = "EN">
<head>
<Meta charset = "UTF-. 8">
<title> Books </ title>
</ head>
<body>
<H2> Books information </ h2>
{% for b in paginate.items%}
number: {{b.id}}
title: {} {} b.name
<br>
{%} endfor%
pages: {{paginate.pages}}
data bus Article number: {{paginate.total}}
pages: {} {} paginate.page
<a href="/booklist/?page=1"> Home </a>
{%} IF paginate.has_prev%
<A href = "/ booklist /? page = {{paginate.prev_num}}"> Previous </a>
{% endif%}
{IF the paginate%.has_next %}
<a href="/booklist/?page={{ paginate.next_num }}">下一页</a>
{% endif %}
<a href="/booklist/?page={{paginate.pages}}">尾页</a>
页码:
{% for i in paginate.iter_pages() %}
<a href="/booklist/?page={{ i }}">{{ i }}</a>
{% endfor %}
</body>
</html>


 

Guess you like

Origin www.cnblogs.com/Jokerguigui/p/11531968.html
Recommended