Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ValueError at /blog/password_change/blue/
- The view blog.views.password_change didn't return an HttpResponse object. It returned None instead.
- url(r'^password_change/(?P<username>[-w.]+)/$', views.password_change, name='password_change'),
- url(r'^password_change_done/$', views.password_change_done, name='password_change_done'),
- class PasswordChangeForm(SetPasswordForm):
- error_messages = dict(SetPasswordForm.error_messages, **{
- 'password_incorrect': ("Your old password was entered incorrectly. Please enter it again."),
- })
- oldpassword = forms.CharField(
- label=("Old password"),
- strip=False,
- widget=forms.PasswordInput(attrs={'autofocus': True}),
- )
- field_order = ['oldpassword', 'password1', 'password2']
- def clean_oldpassword(self):
- oldpassword = self.cleaned_data["oldpassword"]
- if not self.user.check_password(oldpassword):
- raise forms.ValidationError(
- self.error_messages['password_incorrect'],
- code='password_incorrect',
- )
- return oldpassword
- @login_required
- def password_change(request, username):
- if request.method == 'POST':
- form = PasswordChangeForm(data=request.POST, user=request.user)
- if form.is_valid():
- oldpassword = form.cleaned_data.get('oldpassword')
- password1 = form.cleaned_data.get('password1')
- password2 = form.cleaned_data.get('password2')
- if password1 == password2:
- update_session_auth_hash(request, form.username)
- form.save()
- return HttpResponseRedirect('/blog/password_change_done/')
- else:
- return render(request, 'blog/detail.html', {'error_message': 'password mismatch'})
- else:
- form = PasswordChangeForm(user=request.user)
- return redirect(reverse('blog:profile', args=[form.user.get_username()]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement