From 54d09469f5bb073e88ca24046662cab7b8c2364b Mon Sep 17 00:00:00 2001 From: unknown <614792301@qq.com> Date: Tue, 2 Jul 2024 16:19:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBug564?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin_service.py | 22 +++++++++++----------- app/templates/admin_manage_article.html | 12 +++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/admin_service.py b/app/admin_service.py index c461af9..9cd093a 100644 --- a/app/admin_service.py +++ b/app/admin_service.py @@ -79,18 +79,18 @@ def article(): "username": session.get("username"), } - - if request.method == "GET": - try: - delete_id = int(request.args.get("delete_id", 0)) - except: - return "Delete article ID must be integer!" - if delete_id: # delete article - delete_article_by_id(delete_id) - _update_context() - - elif request.method == "POST": + if request.method == "POST": data = request.form + + if "delete_id" in data: + try: + delete_id = int(data["delete_id"]) # 转成int型 + delete_article_by_id(delete_id) # 根据id删除article + flash(f'Article ID {delete_id} deleted successfully.') # 刷新页首提示语 + _update_context() + except ValueError: + flash('Invalid article ID for deletion.') + content = data.get("content", "") source = data.get("source", "") question = data.get("question", "") diff --git a/app/templates/admin_manage_article.html b/app/templates/admin_manage_article.html index 272b54e..5849e10 100644 --- a/app/templates/admin_manage_article.html +++ b/app/templates/admin_manage_article.html @@ -7,6 +7,11 @@ content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" /> + @@ -66,9 +71,10 @@
{% for text in text_list %}
-
- 删除 -
+
+ + +
{{ text.title }}
From 3383e411ec7e271bfee5adea8c267c78570e5e97 Mon Sep 17 00:00:00 2001 From: JiangChao <614792301@qq.com> Date: Wed, 3 Jul 2024 15:19:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Fix=20bug=20564=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/admin_service.py b/app/admin_service.py index 9cd093a..2a295af 100644 --- a/app/admin_service.py +++ b/app/admin_service.py @@ -89,7 +89,7 @@ def article(): flash(f'Article ID {delete_id} deleted successfully.') # 刷新页首提示语 _update_context() except ValueError: - flash('Invalid article ID for deletion.') + flash('Invalid article ID for deletion.') # 刷新页首提示语 content = data.get("content", "") source = data.get("source", "") @@ -99,9 +99,9 @@ def article(): if level not in ['1', '2', '3', '4']: return "Level must be between 1 and 4." add_article(content, source, level, question) - _update_context() title = content.split('\n')[0] flash(f'Article added. Title: {title}') + _update_context() # 这行应在flash之后 否则会发生新建的文章即点即删 return render_template("admin_manage_article.html", **context)