fix: fix the pagination

吴宇涵 2023-03-23 13:47:53 +08:00
parent bdda754af6
commit ec6a2249ae
2 changed files with 7 additions and 11 deletions

View File

@ -25,14 +25,10 @@ def admin():
article_number = get_number_of_articles()
try:
_page_size = min(int(request.args.get("size", 5)), article_number)
if _page_size <= 0:
raise ZeroDivisionError
_cur_page = min(int(request.args.get("page", 1)), article_number // _page_size)
_page_size = min(max(1, int(request.args.get("size", 5))), article_number) # 最小的size是1
_cur_page = min(max(1, int(request.args.get("page", 1))), article_number // _page_size + 1) # 最小的page是1
except ValueError:
return "page parmas must be int!"
except ZeroDivisionError:
return "page size must bigger than zero"
context = {
"article_number": article_number,

View File

@ -101,17 +101,17 @@
</div>
<div style="margin:20px 0;">
<ul class="pagination pagination-sm justify-content-center">
<li class="page-item"><a class="page-link" href="/admin?page={{cur_page-1}}&size={{page_size}}">Previous</a>
<li class="page-item"><a class="page-link" href="/admin?page={{ cur_page - 1 }}&size={{ page_size }}">Previous</a>
</li>
{% for i in range(1, article_number//page_size+1) %}
{% for i in range(1, article_number // page_size + 2) %}
{% if cur_page == i %}
<li class="page-item active"><a class="page-link" href="/admin?page={{i}}&size={{page_size}}">{{ i }}</a>
<li class="page-item active"><a class="page-link" href="/admin?page={{ i }}&size={{ page_size }}">{{ i }}</a>
</li>
{% else %}
<li class="page-item"><a class="page-link" href="/admin?page={{i}}&size={{page_size}}">{{ i }}</a></li>
<li class="page-item"><a class="page-link" href="/admin?page={{ i }}&size={{ page_size }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
<li class="page-item"><a class="page-link" href="/admin?page={{cur_page+1}}&size={{page_size}}">Next</a>
<li class="page-item"><a class="page-link" href="/admin?page={{ cur_page + 1 }}&size={{ page_size }}">Next</a>
</li>
</ul>
</div>