Django - 自定义身份验证后端中的错误消息
我通过扩展默认的 ModelBackend 编写了一个自定义身份验证后端。是否可以向登录屏幕发送自定义错误消息?截至目前,它显示的是默认消息。
I have written a custom auth backend by extending the defalut ModelBackend. Is it possible to send a custom error message to login screen? As of now it is displaying the default message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以引发 django ValidationError
然后可以使用以下命令显示它:
You can raise a django ValidationError
You can then display it with:
错误消息是由
django.contrib.auth.forms.AuthenticationForm
引发的ValidationError
异常。您需要扩展身份验证表单或实现您自己的身份验证表单来更改其错误消息。The error messages are coming as
ValidationError
exceptions raised bydjango.contrib.auth.forms.AuthenticationForm
. You would need to extend the Authentication Form or implement your own authentication form to change it's error messages.