Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Well I am using django 3.0.3 and python 3.8.5..
ValidationError is not raising error even I am entering different emials...
I have tried so many possible way to raise error but non of them work..

What I have tried:

Python
------forms.py-------

 class FormName(forms.Form):
        name = forms.CharField( required=True)
        email = forms.EmailField( required=True)
        vmail  = forms.EmailField( required=True)
        text = forms.CharField(widget = forms.Textarea)
    
    
    
    def clean(value):
        cleaned_data = super().clean()
        name = cleaned_data.get("name")
        email = cleaned_data.get("email")
        vmail = cleaned_data.get("vmail")
    
        if email != vmail:
            raise ValidationError("Emails are not match")

--------views.py-----

    def forms_web(request):
        forming = forms.FormName()
        if request.method == 'POST':
            forming = forms.FormName(request.POST)
    
            if forming.is_valid():
                print("VALIDATION SUCCESS!")
                print("NAME :" +forming.cleaned_data['name'])
                print("EMAIL :" +forming.cleaned_data['email'])
                print("VMAIL :" +forming.cleaned_data['vmail'])
                print("TEXT :" +forming.cleaned_data['text'])
        
        return render(request ,'django_App/forms.html',{'form':forming})
Posted
Updated 19-Aug-20 17:58pm
v2
Comments
Richard MacCutchan 20-Aug-20 4:52am    
Without the data that you are running with it is impossible to tell. Use the debugger to find out what happens when you execute the comparison of the two emails. I alos noticed the following two lines:
email = forms.EmailField( required=True)
vmail  = forms.EmailField( required=True)

Is it correct that they both refer to the same form item?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900