Here I need to add an extra confirmation password
in my form.I used Django\'s modelform. I also need to validate both passwords. It must raise a validation error if
Try this for forms.py:
class UserForm(forms.Form):
password = forms.CharField(widget=forms.PasswordInput())
password_confirm = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields=('username','email','password')
And this in views.py:
if user_form.is_valid() and profile_form.is_valid() and user_form.cleaned_data['password'] == user_form.cleaned_data['password_confirm']:
...
elif user_form.data['password'] != user_form.data['password_confirm']:
user_form.add_error('password_confirm', 'The passwords do not match')