From d0cb531c20cf0c94a37f14408f79e096cd7e41b8 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Wed, 19 Aug 2026 16:02:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=AA=E7=99=BB=E5=BD=95=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=20500=E2=80=94=E2=80=94login=5Fview=20=E8=93=9D?= =?UTF-8?q?=E5=9B=BE=E5=8C=96=E5=90=8E=E6=9C=AA=E6=9B=B4=E6=96=B0=E4=B8=BA?= =?UTF-8?q?=20auth.login=EF=BC=8Cflask=5Flogin=20=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=20url=5Ffor('login')=20BuildError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/regression_test.py | 12 ++++++++++++ web_server.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/regression_test.py b/scripts/regression_test.py index b922df2..555bc33 100644 --- a/scripts/regression_test.py +++ b/scripts/regression_test.py @@ -93,6 +93,18 @@ def main(): fails.append(f"GET {rule} -> {type(e).__name__}: {e}") print(f"GET 路由: {len(rules)} 个(跳过 {len([r for r in rules if r.startswith(_SKIP_PREFIXES)])} 个流式/二进制)") + # ========== 1.5 未登录访问(登录重定向链路) ========== + try: + r = c.get("/") + if r.status_code == 302 and "login" in (r.headers.get("Location") or ""): + passed += 1 + elif r.status_code == 200: + passed += 1 # 已登录态也可能 200(测试客户端无 cookie 时走 302) + else: + fails.append(f"未登录访问 / -> HTTP {r.status_code}(应 302 到登录页)") + except Exception as e: + fails.append(f"未登录访问 / -> {type(e).__name__}: {e}") + # ========== 2. 写操作空 body 探测(抓 import 遗漏/引用错误) ========== write_rules = sorted({r.rule for r in app.url_map.iter_rules() if r.rule.startswith("/api") diff --git a/web_server.py b/web_server.py index 3cbdcf4..3396e2a 100644 --- a/web_server.py +++ b/web_server.py @@ -37,7 +37,7 @@ app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join( app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False login_manager = LoginManager(app) -login_manager.login_view = "login" +login_manager.login_view = "auth.login" # 蓝图化后路由前缀 auth # 先初始化数据库(含旧 JSON 迁移),再创建 TaskManager(需要 app context 读写 DB) init_db(app)