Flask page, flask

Source: Internet
Author: User

Flask page, flask

 

 

We will encounter such problems during our learning process, that is, we will find that paging is required during our learning process. Here, we will introduce the pagination mentioned in the book.

 

 

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

This is the paging data that I read from the database. How can we paging the data?

 

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

{% macro pagination_widget(pagination, endpoint) %}<ul class="pagination"><li{% if not pagination.has_prev %} class="disabled"{% endif %}><a style='background-color: lightgoldenrodyellow;color: brown;' href="{% if pagination.has_prev %}{{ url_for(endpoint,page = pagination.page - 1, **kwargs) }}{% else %}#{% endif %}">«</a></li>{% for p in pagination.iter_pages() %}{% if p %}{% if p == pagination.page %}<li class="active"><a style='background-color: lightgoldenrodyellow;color: brown;' href="{{ url_for(endpoint, page = p, **kwargs) }}">{{ p }}</a></li>{% else %}<li><a style='background-color: lightgoldenrodyellow;color: brown;' href="{{ url_for(endpoint, page = p, **kwargs) }}">{{ p }}</a></li>{% endif %}{% else %}<li class="disabled"><a href="#">…</a></li>{% endif %}{% endfor %}<li{% if not pagination.has_next %} class="disabled"{% endif %}><a  style='background-color: lightgoldenrodyellow;color: brown;' href="{% if pagination.has_next %}{{ url_for(endpoint,page = pagination.page + 1, **kwargs) }}{% else %}#{% endif %}">»</a></li></ul>{% endmacro %}

So how can we use it?

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

Add the following

Effect

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.