Django-allauth:成功登录的PasswordChangeView覆盖,错误的注销用户结果

问题描述 投票:0回答:1

通过django-allauth更改密码时,成功发布密码更改后的默认重定向再次是密码更改模板。由于我感到困惑,因此我在views.py文件中覆盖了原来的PasswordChnageView:

from allauth.account.views import PasswordChangeView
from django.urls import reverse_lazy

class MyPasswordChangeView(PasswordChangeView):
    success_url = reverse_lazy('home')

并更改了我的urls.py文件:

from django.urls import path, include
from users.views import MyPasswordChangeView 

urlpatterns = [
        ...
        # User management
        path('accounts/password/change/', MyPasswordChangeView.as_view(), name="account_change_password"),
        path('accounts/', include('allauth.urls')),
        ...
    ]

这在用户登录时工作正常,但是当我尝试在注销时访问URL http://127.0.0.1:8000/accounts/password/change/时,出现以下错误消息:AttributeError at /accounts/password/change/ 'AnonymousUser' object has no attribute 'has_usable_password'在创建自定义替代之前,相同行为的结果是我被重定向到了登录网址http://127.0.0.1:8000/accounts/login/?next=/

我需要在自定义视图中进行哪些更改,以在注销的用户尝试访问URL http://127.0.0.1:8000/accounts/password/change/时重定向到登录URL>

通过django-allauth更改密码时,成功发布密码更改后的默认重定向再次是密码更改模板。由于我感到困惑,因此覆盖了...

django django-views django-authentication django-allauth
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.