[英]Django How to add a logout successful message using the django.contrib.auth?
I am not using all-auth
我没有使用all-auth
I am using the standard authentication system and url's provided by django.contrib.auth
. 我正在使用django.contrib.auth
提供的标准身份验证系统和url。
I have also ensured that when logging out the user is automatically redirected to the login page 我还确保注销时,用户会自动重定向到登录页面
LOGOUT_REDIRECT_URL = "login"
I would like to add a message so the user knows they have been logged out like: 我想添加一条消息,以便用户知道他们已经被注销,例如:
from django.contrib import messages
messages.add_message(request, messages.INFO, 'You have been logged out.')
Would I be able to achieve this without making my own view to logout. 我能够在不做出自己的退出视图的情况下实现这一目标。 Could I use signals
? 我可以使用signals
吗?
You can use user_logged_out
signal 您可以使用user_logged_out
信号
from django.contrib.auth.signals import user_logged_out
from django.contrib import messages
def show_message(sender, user, request, **kwargs):
# whatever...
messages.info(request, 'You have been logged out.')
user_logged_out.connect(show_message)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.