django user logged out after password change

后端 未结 3 1745
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 10:43

I am having an issue with Django users changing passwords - I have built a few production sites in Django, just none in about a year (or in 1.8), but I don\'t recall having this

3条回答
  •  滥情空心
    2021-02-02 11:25

    For django 1.9:

    from django.contrib.auth import update_session_auth_hash
    
    def password_change(request):
        if request.method == 'POST':
            form = PasswordChangeForm(user=request.user, data=request.POST)
            if form.is_valid():
                form.save()
                update_session_auth_hash(request, form.user)
    

    The following fields must be supplied in the POST request:

    • old_password
    • new_password1
    • new_password2

    See detailed docs at https://docs.djangoproject.com/en/1.9/topics/auth/default/#session-invalidation-on-password-change

提交回复
热议问题