简体   繁体   English

Django:会话相当于@user_passes_test

[英]Django: Session equivalent of @user_passes_test

I'm familiar with the @user_passes_test auth decorator, I'm wondering if there is an equivalent for sessions? 我熟悉@user_passes_test auth装饰器,我想知道是否有相应的会话? Basically I have an account settings page, before heading to the page the user confirms their password, if they succeed then a time stamp is added as a key to their session. 基本上我有一个帐户设置页面,在前往用户确认其密码的页面之前,如果成功,则会将时间戳添加为其会话的密钥。 I would like to wrap all the other "profile settings" views in a "session passes test" style decorator, which confirms that both the time stamp exists and is less than a certain amount of time old. 我想在“会话通过测试”样式装​​饰器中包装所有其他“配置文件设置”视图,这确认时间戳存在并且小于一定的时间。 Is there an easy way to do this? 是否有捷径可寻? I have several views that need the same logic. 我有几个需要相同逻辑的视图。 So repeating a large chunk of code in each is somewhat obnoxious. 因此,在每个代码中重复大量代码有点令人讨厌。

perhaps you want to just write your own decorator to encapsulate all the session logic you want, and apply it to all the "profile settings" views 也许您只想编写自己的装饰器来封装所需的所有会话逻辑,并将其应用于所有“配置文件设置”视图

eg How to make a chain of function decorators? 例如, 如何建立一个功能装饰链? (they're basically a function which returns a function etc. etc.) (它们基本上是一个返回功能等的功能)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM