From ec6a2249ae32f7748e5d0d231e27042ed6fca39b Mon Sep 17 00:00:00 2001 From: Awoodwhale Date: Thu, 23 Mar 2023 13:47:53 +0800 Subject: [PATCH] fix: fix the pagination --- app/admin_service.py | 8 ++------ app/templates/admin_index.html | 10 +++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/admin_service.py b/app/admin_service.py index de05b46..717d4b4 100644 --- a/app/admin_service.py +++ b/app/admin_service.py @@ -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, diff --git a/app/templates/admin_index.html b/app/templates/admin_index.html index 985ece0..ed5eecd 100644 --- a/app/templates/admin_index.html +++ b/app/templates/admin_index.html @@ -101,17 +101,17 @@