Hi, Dev’s👏, Let’s see How to match password and confirm password field values in Django?
In the forms. py file you create a form and in that form, you create a clean method that overrides the default clean method, and there you can get your cleaned submitted values.
The call to super().clean() ensures that any validation logic present in the parent class is maintained.
Example
from django import forms
class StudentRegistration(forms.Form):
name = forms.CharField()
password = forms.CharField(widget = forms.PasswordInput)
confirmpassword = forms.CharField(widget = forms.PasswordInput)
def clean(self):
cleaned_data = super().clean()
p1 = cleaned_data["password "]
p2 = cleanded_data["confirmpassword "]
if p1 != p2:
raise forms.ValidationError("password does not match")
In the Next Article we are going to see Styling Form Field Errors😁, So
Thanks for Following and Claps😋
Link to Day 32