Detailed introduction to flask paging

零下一度
Release: 2017-06-27 09:53:08
Original
2007 people have browsed it

In the process of learning, we will encounter such a problem, 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('/') 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('home1.html', posts=posts, pagination=pagination, tuijian_post=tuijian_post,fenleis=fenlei, links=link)
Copy after login

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.

{% macro pagination_widget(pagination, endpoint) %} 
    « {% for p in pagination.iter_pages() %} {% if p %} {% if p == pagination.page %}
  • {{ p }}
  • {% else %}
  • {{ p }}
  • {% endif %} {% else %}
  • {% endif %} {% endfor %} »
{% endmacro %}
Copy after login

So how do we use it

{% import "mac.html" as macros %}
Copy after login

Add the following

## after our loop

# The effect is as shown

The above is the detailed content of Detailed introduction to flask paging. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!