Home >Backend Development >Python Tutorial >Detailed explanation of examples of paging effect using python flask

Detailed explanation of examples of paging effect using python flask

零下一度
零下一度Original
2017-06-29 15:31:052616browse

This article mainly introduces in detail python flask to achieve pagination effect. It has certain reference value. Interested friends can refer to it.

We will encounter such a problem in the process of learning, that is, in the process of learning, we will find that paging is needed. Here, I will introduce to you the paging mentioned in the book.


@app.route('/',methods=['GET'])
@app.route(&#39;/<int:page>&#39;)
def home(page=1):
  pagination=Post.query.order_by(Post.publish_date.desc()).paginate(page, per_page=10,error_out=False)
  posts = pagination.items
  link,tuijian_post,fenlei=get_tui_link()
  return render_template(&#39;home1.html&#39;,
              posts=posts,
              pagination=pagination,
              tuijian_post=tuijian_post,fenleis=fenlei,        
              links=link)

This is the paginated data I read from the database, so how do we paginate? Let’s see what the book says

Then we need to use a separate page to save our paging-related information.

So how do we use it


{% import "mac.html" as macros %}

Add the following after our loop

The effect is as shown

The above is the detailed content of Detailed explanation of examples of paging effect using python flask. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn