Flask-Login 蓝图设置 session 过期时间

14次阅读
没有评论

共计 577 个字符,预计需要花费 2 分钟才能阅读完成。

业务需要设置 1 小时未操作网页则过期重新登陆。
因为 login 视图在蓝图 auth.py 中,在 auth.py 中以下设置不起作用。

auth = Blueprint('auth', __name__)
@login.route('/login', methods=['GET', 'POST'])
def login():
    login_user(user)
    session.permanent = True
    app.permanent_session_lifetime = timedelta(hours=1)

此时只需要分别在 auth.py 中设置 session.permanent
在 app.py 中设置 app.permanent_session_lifetime 即可。

auth = Blueprint('auth', __name__)
@login.route('/login', methods=['GET', 'POST'])
def login():
    login_user(user)
    session.permanent = True

app.permanent_session_lifetime = timedelta(hours=1)
app.register_blueprint(auth, url_prefix='/auth')

转载自:https://www.jianshu.com/p/8a49a892c0d9

正文完
觉得有用?欢迎赞赏,感谢!
post-qrcode
 0
苏维歌
版权声明:本站原创文章,由 苏维歌 2022-06-06发表,共计577字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码