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

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

我正在用烧瓶建立一个网站,用户有帐户并且能够登录。 我正在使用flask-principal进行部分日志和角色管理。 说5分钟或10分钟后,用户的会话是否有效? 我无法在flask文档或flask-principal的文档中找到它。

我想到了一个手动的方法,设置一个变量服务器端在登录的时候带有时间标签,在用户下一个动作时,服务器验证该时间戳上的时间差,并删除会话。

解决方案

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

from datetime从flask导入会话导入timedelta , @ app.before_request def make_session_permanent(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes = 5)

默认情况下,在Flask中,permanent_session_lifetime设置为31天。

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 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)

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

更多推荐

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

本文发布于:2023-05-28 06:54:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

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

>www.elefans.com

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