简体   繁体   English

检测刚刚在Django中登录了上下文处理器的用户

[英]Detect user just logged in context processor in Django

I need to show users some banners depending on certain situations. 我需要根据特定情况向用户显示一些横幅。 One of those situations is a moment, when user just logged in. 这些情况之一就是用户刚刚登录的片刻。

How can I detect in django 1.4 context processor login moment? 如何在django 1.4上下文处理器中检测登录时刻? I know about django.contrib.auth.signals.user_logged_in signal, but I have no idea, how can I use check it in context processor. 我知道django.contrib.auth.signals.user_logged_in信号,但是我不知道如何在上下文处理器中使用它。

How can I do this? 我怎样才能做到这一点? Or is there another ways to detect users login event in context processor? 还是有其他方法可以检测上下文处理器中的用户登录事件? May be there is the way to create signal handler, which will set some variable in request object, and in context processor I would check it. 可能存在创建信号处理程序的方法,该方法将在请求对象中设置一些变量,在上下文处理器中,我将对其进行检查。 Or some other way. 或其他方式。

您可以在登录视图中设置会话,并在使用后销毁它。

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

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