Django - Error Message in Custom Auth Backend

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:13:35

问题


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.


回答1:


The error messages are coming as ValidationError exceptions raised by django.contrib.auth.forms.AuthenticationForm. You would need to extend the Authentication Form or implement your own authentication form to change it's error messages.




回答2:


You can raise a django ValidationError

from django.core.exceptions import ValidationError

raise ValidationError("Some custom message")

You can then display it with:

{{ form.non_field_errors|striptags }}


来源:https://stackoverflow.com/questions/5523928/django-error-message-in-custom-auth-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!