我正在尝试将我的应用程序配置为在一定时间后使cookie过期,但是它们无法按预期工作,我的cookie根本不会过期。
我的app.py文件中具有以下配置:
from flask_login import LoginManager
from datetime import timedelta
app.config['REMEMBER_COOKIE_DURATION'] = timedelta(seconds=30)
login = LoginManager(app)
login.init_app(app)
login.login_view = 'login'
以下是我的Remember_me输入:
<input type="checkbox" class="form-check-input" id="remember_me" name="remember_me">
<label class="form-check-label" for="remember_me">Remember me for 1 week</label>
最后,以下是我的查看功能:
@app.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return flask.redirect(flask.url_for('home'))
if flask.request.method == 'POST':
member_username = flask.request.form['member_username']
member_password = flask.request.form['member_password']
remember_me = flask.request.form.get('remember_me')
existing_user = Users.query.filter_by(username=member_username).first()
if existing_user is None or not existing_user.check_password(member_password):
flask.flash('Invalid username or password')
return flask.redirect(flask.url_for('login'))
if existing_user:
login_user(existing_user, remember=remember_me)
next_page = flask.request.args.get('next')
if not next_page or url_parse(next_page).netloc != '':
next_page = flask.url_for('home')
return flask.redirect(next_page)
return flask.render_template('login.html')
我已经关注的资源: https://code.luasoftware.com/tutorials/flask/how-to-configure-flask-login/ https://www.youtube.com/watch?v=CRvV9nFKoPI flask-login: Chrome ignoring cookie expiration?
我想念什么?
答案 0 :(得分:0)
我有同样的问题,添加 PERMANENT_SESSION_LIFETIME 对我有用。我的理解是 REMEMBER_COOKIE_DURATION 和 PERMANENT_SESSION_LIFETIME 都会影响会话何时到期。
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(seconds=30)