Day 31 of 100 Days of Django: Match Two Form Field Values in Django.

Aman Khan
Aug 17, 2022

--

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

Link to Starter Page

--

--

Aman Khan

Blockchain and Web3 Engineer Crafting compelling stories at the intersection of tech, business, and culture.