Last active
January 30, 2018 14:09
-
-
Save HViktorTsoi/5aa6683d73ab8087ce0bff3222fb3871 to your computer and use it in GitHub Desktop.
Flask-Jinjia2 Pagination template, the pattern is like '/display/<page_number>'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro pager(_uri, total, limit, curr_page, left=3, right=7) -%} | |
{% set uri=_uri %} | |
{% if total > limit %} | |
{% set page_num = total//limit if total%limit==0 else total//limit+1 %} | |
{% set pre_page = curr_page - 1 %} | |
{% set pre_page = 1 if pre_page < 1 else pre_page %} | |
{% set next_page = curr_page + 1 %} | |
{% set next_page = page_num if next_page > page_num else next_page %} | |
{% set begin_idx = 1 if curr_page <= 3 else curr_page - left %} | |
{% set end_idx = begin_idx + right %} | |
{% set end_idx = page_num if end_idx > page_num else end_idx %} | |
<ul class="pagination pagination-sm"> | |
{%if curr_page > 1 %} | |
<li><a href="{{uri}}/1">首页</a></li> | |
<li><a href="{{uri}}/{{pre_page}}"><</a></li> | |
{%else%} | |
<li class="disabled"><a>首页</a></li> | |
<li class="disabled"><a><</a></li> | |
{%endif%} | |
{% for idx in range(begin_idx, end_idx+1) %} | |
<li class="{%if curr_page == idx %}active{%endif%}"> | |
<a href="{{uri}}/{{idx}}">{{idx}}</a> | |
</li> | |
{% endfor %} | |
{%if curr_page < page_num %} | |
<li><a href="{{uri}}/{{next_page}}">></a></li> | |
<li><a href="{{uri}}/{{page_num}}">尾页</a></li> | |
{%else%} | |
<li | |
class="disabled"><a>></a></li> | |
<li | |
class="disabled"><a>尾页</a></li> | |
{%endif%} | |
</ul> | |
{%endif%} | |
{%- endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment