Django newbie here. I am trying to raise an error for email field in my custom form. My forms.py has following code to validate email:
def clean_email(self):
email = self.cleaned_data["email"]
try:
User._default_manager.get(email=email)
except User.DoesNotExist:
return email
raise ValueError({'email':'Email already registered.
Login to continue or use another email.'})
On entering existing email again, I get following error on my debug screen of app:
What am I doing wrong here? I am following this LINK
EDIT
Getting this error on changing ValueError to ValidationError The argument field
must be None
when the error
argument contains errors for multiple fields.
Use raise ValidationError
instead of raise ValueError
:
def clean(self):
email = self.cleaned_data["email"]
try:
User._default_manager.get(email=email)
except User.DoesNotExist:
return self.cleaned_data
raise ValidationError({'email':'Email already registered. Login to continue or use another email.'})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With