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