From c9e70a7317002c8fe68c415781718f9b3ab5ba98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD?= Date: Thu, 12 Mar 2026 10:54:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=93=8D=E5=BA=94=E5=A4=B4=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E7=BC=93=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 HTML 页面添加 Cache-Control: no-cache - 添加 Pragma: no-cache - 添加 Expires: 0 - 解决用户浏览器缓存旧版本 HTML 的问题 --- app.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 430ed8a..351a121 100644 --- a/app.py +++ b/app.py @@ -6,7 +6,7 @@ 作者:小白 🐶 """ -from flask import Flask, render_template, redirect, url_for, request, flash +from flask import Flask, render_template, redirect, url_for, request, flash, make_response from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user from flask_sqlalchemy import SQLAlchemy from werkzeug.security import generate_password_hash, check_password_hash @@ -18,6 +18,16 @@ app.config['SECRET_KEY'] = 'xiaobai-secret-key-2026' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +# 禁用缓存 - 解决浏览器缓存问题 +@app.after_request +def add_no_cache_headers(response): + """为 HTML 页面添加禁用缓存的响应头""" + if 'text/html' in response.content_type: + response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate' + response.headers['Pragma'] = 'no-cache' + response.headers['Expires'] = '0' + return response + # 初始化数据库 db = SQLAlchemy(app)