Django:所有具有电子邮件的身份验证帐户-唯一约束失败。显示消息而不是给出错误 [英] Django: all auth create account with email - unique constraint failed. Display message instead of giving an error
问题描述
我正在使用djnago all-auth创建自定义用户帐户。使用电子邮件和密码创建帐户时,如果具有电子邮件帐户已经退出,则会出现错误(UNIQUE约束失败:account_emailaddress.email),但我想显示一条消息,指出该电子邮件帐户已经存在,而不是抛出错误。处理此问题的最佳方法是什么?通常,我将使用AJAX来验证和显示我自己的视图的消息,但是我不知道如何在这里处理django all-auth软件包。
I am using djnago all-auth to create custom user accounts. When creating an account with email and password, if account with a email already exits it gives an error (UNIQUE constraint failed: account_emailaddress.email) but I would like to display message that an account with this email already exists instead of throwing an error. What is the best way to handle this? In general I would use AJAX to verify and display message for my own views but I do not know how to deal here with django all-auth package.
推荐答案
我建议您应覆盖注册/登录表单以管理此错误。您检查过文档了吗? https://django-allauth.readthedocs.io/en/latest/forms。 html
I'll suggest that you should override the signup/login form in order to manage this error. Have you checked the documentation? https://django-allauth.readthedocs.io/en/latest/forms.html
我认为此答案与
- 创建继承
SignupView
并覆盖表单类的自定义视图 - 创建一个自定义表单,该表单继承自
SignupForm
并覆盖电子邮件验证消息 - 在您自己的urls.py在
include('allauth.urls')
之后添加以下内容以覆盖account_signup
url
- Create your custom view that inherits
SignupView
and overrides the form class - Create a custom form that inherits from
SignupForm
and overrides the email validation message - In your own urls.py add the following after
include('allauth.urls')
to override theaccount_signup
url
这篇关于Django:所有具有电子邮件的身份验证帐户-唯一约束失败。显示消息而不是给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!