# views.py @render_to('edit_password.html') def edit_password(request): if request.method == 'POST': form = EditPasswordForm(request, request.POST) if form.is_valid(): pass else: return {'form': form} form = EditPasswordForm() return {'form': form} # forms.py class EditPasswordForm(forms.Form): def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(EditPasswordForm, self).__init__(*args, **kwargs) old_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'})) new_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'})) new_password_confirmation = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'})) def clean(self): if not check_password(request.user, self.cleaned_data['old_password']): raise forms.ValidationError(u"Old password isnt correct") if self.cleaned_data['new_password'] != self.cleaned_data['new_password_confirmation']: raise forms.ValidationError(u"password didnt match") return self.cleaned_data