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.
Asked
Active
Viewed 696 times
2 Answers
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:
- 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

pyjavo
- 1,598
- 2
- 23
- 41
-
I am already doing that. My question is if someone tried create an account with the email that already exists then it is throwing an error but I want to display the message that an account with this email already exits. Is there any way to that by changing the settings. I am thinking to write AJAX call function in the frontend to verify if the email already exits then submitting the signup form. Is there any better way than this using django all-auth. Thanks! – sreekanthkura7 May 01 '20 at 03:56
-
I don't think AJAX is necessary (Is a good idea though). You need to customize the django allauth forms and views properly. You might need to check the original repo for inspiration. I updated my answer with a similar approach I found @sreekanthkura7 – pyjavo May 03 '20 at 17:49
0
Since djangoallauth take care of unique constrain you don't have to add unique=True to your field if user try to login with any social media account with email id already present in your database it djangoallauth will simple ignore and will not set email id in your user model. :) I am handling my unique fields i.e Email field manually

Aditya Rawas
- 1
- 2
- 1