Django validate fileds on form

I can`t understand how to return error in template I making check on valid in my from

FORMS.py

class UserForm(forms.Form):
    first_name= forms.CharField(max_length=20, label='Name')
    last_name= forms.CharField(max_length=20, label='Last_name')
    password= forms.CharField(label='Password')
    repassword= forms.CharField(label='Confirm password')
    
    def clean(self):
        cleaned_data = super().clean()
        self.password = cleaned_data('password')
        self.repassword = cleaned_data('repassword')
        if self.password != self.repassword:
            raise ValidationError('Password dont match')

VIEW.py

def index(request):
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST or None)
        if form.is_valid():
            firstname= form.cleaned_data.get("first_name")
            lastname= form.cleaned_data.get("last_name")
            password = form.cleaned_data.get('password')
            re_password = form.cleaned_data.get('repassword')
     form = UserForm()
            context = {'form': form,
                    }
            return render(request, 'create_users/index.html', context)
    return render(request, 'create_users/index.html', {'form': form}

As result i see this when update my template

    dict' object is not callable

There is a syntax error in your clean method.

    def clean(self):
        cleaned_data = super().clean()
        # self.password = cleaned_data('password')
        self.password = cleaned_data.get('password')
        # self.repassword = cleaned_data('repassword')
        self.repassword = cleaned_data.get('repassword')
        if self.password != self.repassword:
            raise ValidationError('Password dont match')
Back to Top