重置Flask中cookie的到期时间 [英] Resetting the expiration time for a cookie in Flask
本文介绍了重置Flask中cookie的到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
main
的应用程序,我已经设置了 main.permanent_session_lifetime = timedelta(days = 5)
,所以即一个用户在登录后将保持登录状态5天,但即使是一个活跃的用户也会在5天后注销。我希望每次访问网站时都要重置到期时间,因此只有在不活动的5天后才能注销。大多数网站都是这样工作的如何使用Flask执行此操作?解决方案
您可以使用 @before_request
处理程序。
请尝试以下操作:
@ app.before_request
def func():
session.modified = True
I'm using the the Python web framework Flask. I use sessions in my app. For my app called main
, I've got the setting main.permanent_session_lifetime = timedelta(days=5)
, so that a user will remain logged in for 5 days after logging in. But even an active user will be logged out after 5 days. I would like the expiration time to reset each time they visit the site, so you get logged out only after 5 days of inactivity. Most sites work this way. How do I do that with Flask?
解决方案
You can renew the session to the client at each request using a @before_request
handler.
Try the following:
@app.before_request
def func():
session.modified = True
这篇关于重置Flask中cookie的到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文