0
パスワードを変更してユーザープロファイルを表示する次の機能がありますが、'profile/'
ページにリダイレクトされずにフォームを送信すると、The view core.views.change_password didn't return an HttpResponse object. It returned None instead.
というエラーが表示されます。パスワードを変更するDjango
from django.contrib.auth.forms import UserChangeForm, PasswordChangeForm
from django.contrib.auth import update_session_auth_hash
def change_password(request):
if request.method == "POST":
form = PasswordChangeForm(data= request.POST, user = request.user)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user) #this function keeps the user logged in afte they change their password
# request.user could not have been passed in because that would pass in 'AnonymousUser', however
#form.user gets the user who was filling in the form and passes it to the function
return redirect('/profile')
else:
form = PasswordChangeForm(user = request.user)
args = {'form': form} # gives access to the form in the template
return render(request, 'core/change_password.html', args)
def view_profile(request):
args = {'user': request.user} #
return render(request, 'core/profile.html', args)
注:プロファイルページは、ログイン後、ユーザーが問題なくプロファイルページにリダイレクトされた後など、サイトの他の部分でも機能します。
フォームが有効でないとどうなりますか?答え:何もありません。 –