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)