Django: all auth create account with email - unique constraint failed. Display message instead of giving an error

喜欢而已 提交于 2020-06-29 04:18:08

问题


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.


回答1:


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

I think this answer is related to your question.

A relatively similar approach is given in this answer:

  1. Create your custom view that inherits SignupView and overrides the form class
  2. Create a custom form that inherits from SignupForm and overrides the email validation message
  3. In your own urls.py add the following after include('allauth.urls') to override the account_signup url


来源:https://stackoverflow.com/questions/61327185/django-all-auth-create-account-with-email-unique-constraint-failed-display-m

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