如何覆盖Django AuthenticationForm非活动消息

2024-09-30 01:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

当帐户存在但处于非活动状态时,我试图显示自定义错误消息。为此,我超越了AuthenticationForm's{}

forms.py

class AuthForm(AuthenticationForm):
    error_messages = {
        'invalid_login': (
            "This custom message works"
        ),
        'inactive': (
            "This custom message does not."
        ),
    }

url.py

path('login/', auth_views.LoginView.as_view(
        template_name='employees/login.html',
        authentication_form=AuthForm),
         name='login'),

如您所见,非活动消息不起作用。想一想为什么

编辑:当非活动帐户尝试登录时,将显示invalid_login消息,而不是inactive消息


Tags: namepy消息message错误customloginforms

热门问题