Created
October 16, 2015 01:51
-
-
Save cloverstd/900f8450f108a9de0408 to your computer and use it in GitHub Desktop.
Flask macro gist
This file contains 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
{% import 'pagination.html' as pagination %} | |
{% call(page) pagination.paginate(page, last_page) %} | |
{{url_for('manage.order_list')}}?page={{page}}&status={{status}} | |
{% endcall %} |
This file contains 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 paginate(page, last_page) -%} | |
<nav> | |
<ul class="pagination"> | |
{% if page == 1 %} | |
<li class="disabled"> | |
<span aria-label="Previous"> | |
<span aria-hidden="true">«</span> | |
</span> | |
</li> | |
{% else %} | |
<li><a href="{{ caller(1) }}">首页</a></li> | |
<li> | |
<a href="{{ caller(page-1) }}" aria-label="Previous"> | |
<span aria-hidden="true">«</span> | |
</a> | |
</li> | |
{% endif %} | |
{% if last_page <= 5 %} | |
{% for i in range(1, last_page+1) %} | |
{% if page==i %} | |
<li class="active"><span>{{i}}</span></li> | |
{% else %} | |
<li><a href="{{ caller(i) }}">{{i}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% else %} | |
{% if page <= 3 %} | |
{% for i in range(1, 6) %} | |
{% if page==i %} | |
<li class="active"><span>{{i}}</span></li> | |
{% else %} | |
<li><a href="{{ caller(i) }}">{{i}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% elif page + 2 < last_page %} | |
{% for i in range(page - 2, page + 3) %} | |
{% if page==i %} | |
<li class="active"><span>{{i}}</span></li> | |
{% else %} | |
<li><a href="{{ caller(i) }}">{{i}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% else %} | |
{% for i in range(page - 2, last_page+1) %} | |
{% if page==i %} | |
<li class="active"><span>{{i}}</span></li> | |
{% else %} | |
<li><a href="{{ caller(i) }}">{{i}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% endif %} | |
{% endif %} | |
{% if last_page == page %} | |
<li class="disabled"> | |
<span aria-label="Next"> | |
<span aria-hidden="true">»</span> | |
</span> | |
</li> | |
{% else %} | |
<li> | |
<a href="{{ caller(page+1) }}" aria-label="Next"> | |
<span aria-hidden="true">»</span> | |
</a> | |
</li> | |
<li><a href="{{ caller(last_page) }}">末页</a></li> | |
{% endif %} | |
</ul> | |
</nav> | |
{%- endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment