Skip to content Skip to sidebar Skip to footer

Django Change Email/username Already Exists And Email Isn't Valid Error Messages

I'm trying to change these error messages to custom, here's code: >>>forms.py class UserRegistrationForm(forms.ModelForm): ... ... ... def clean_email(self

Solution 1:

Answer is:

defclean_email(self):
        email = self.cleaned_data['email']
        users = User.objects.filter(email__iexact=email)
        if users:
            raise forms.ValidationError("Custom text about email.")
        return email.lower()

    defclean_username(self):
        username = self.cleaned_data['username']
        users = User.objects.filter(username__iexact=username)
        if users:
            raise forms.ValidationError("Custom text about username.")
        return username

I tested it and it works perfectly.

Post a Comment for "Django Change Email/username Already Exists And Email Isn't Valid Error Messages"