有没有一种简单的方法可以使烧瓶中的会话超时?

编程入门 行业动态 更新时间:2024-10-04 11:20:52
本文介绍了有没有一种简单的方法可以使烧瓶中的会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用 Flask 构建一个网站,用户拥有帐户并且可以登录.我正在使用 Flask-principal 进行部分登录和角色管理.有没有办法让用户的会话在 5 分钟或 10 分钟后过期?我在flask 文档或flask-principal 的文档中找不到.

I'm building a website with flask where users have accounts and are able to login. I'm using flask-principal for the loging in part and the role management. Is there a way of making the user's session expire after say 5 minutes or 10 minutes? I was not able to find that in flask documentation or, flask-principal's documentation.

我想到了一种手动完成的方法,在登录时设置一个带有时间标签的变量服务器端,在用户执行的下一个操作中,服务器验证该时间戳上的时间增量并删除会议.

I thought of a way of doing it by hand, set a variable server-side with a time tag at the moment of login and at the next action the user takes, the server verifies the time-delta on that timestamp and deletes the session.

推荐答案

flask 会话一旦关闭浏览器就会过期,除非您有一个永久会话.您可以尝试以下操作:

flask sessions expire once you close the browser unless you have a permanent session. You can possibly try the following:

from datetime import timedelta from flask import session, app @app.before_request def make_session_permanent(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=5)

在 Flask 中,permanent_session_lifetime 默认设置为 31 天.

By default in Flask, permanent_session_lifetime is set to 31 days.

更多推荐

有没有一种简单的方法可以使烧瓶中的会话超时?

本文发布于:2023-11-29 02:09:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:烧瓶   简单   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!