Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. ValueError at /blog/password_change/blue/
  2. The view blog.views.password_change didn't return an HttpResponse object. It returned None instead.
  3.  
  4. url(r'^password_change/(?P<username>[-w.]+)/$', views.password_change, name='password_change'),
  5. url(r'^password_change_done/$', views.password_change_done, name='password_change_done'),
  6.  
  7. class PasswordChangeForm(SetPasswordForm):
  8. error_messages = dict(SetPasswordForm.error_messages, **{
  9. 'password_incorrect': ("Your old password was entered incorrectly. Please enter it again."),
  10. })
  11. oldpassword = forms.CharField(
  12. label=("Old password"),
  13. strip=False,
  14. widget=forms.PasswordInput(attrs={'autofocus': True}),
  15. )
  16.  
  17. field_order = ['oldpassword', 'password1', 'password2']
  18.  
  19. def clean_oldpassword(self):
  20. oldpassword = self.cleaned_data["oldpassword"]
  21. if not self.user.check_password(oldpassword):
  22. raise forms.ValidationError(
  23. self.error_messages['password_incorrect'],
  24. code='password_incorrect',
  25. )
  26. return oldpassword
  27.  
  28. @login_required
  29. def password_change(request, username):
  30. if request.method == 'POST':
  31. form = PasswordChangeForm(data=request.POST, user=request.user)
  32. if form.is_valid():
  33. oldpassword = form.cleaned_data.get('oldpassword')
  34. password1 = form.cleaned_data.get('password1')
  35. password2 = form.cleaned_data.get('password2')
  36. if password1 == password2:
  37. update_session_auth_hash(request, form.username)
  38. form.save()
  39. return HttpResponseRedirect('/blog/password_change_done/')
  40. else:
  41. return render(request, 'blog/detail.html', {'error_message': 'password mismatch'})
  42.  
  43. else:
  44. form = PasswordChangeForm(user=request.user)
  45. return redirect(reverse('blog:profile', args=[form.user.get_username()]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement