post() 得到了意外的关键字参数 'uidb64' 重设密码 rest_auth

post() got an unexpected keyword argument 'uidb64' Reset password rest_auth

现在我使用 rest_auth 重设密码,无论发送什么电子邮件,URL 都像这样打开,但我在上面添加了值: 这是我点击通过电子邮件发送的 URL 时的页面:

在填写字段并发出 post 请求后,我得到了这个: 这是我得到的错误:

这是我的 URLs:

urlpatterns = [
path('', include('rest_auth.urls')),
path('login/', LoginView.as_view(), name='account_login'),
path('registration/', include('rest_auth.registration.urls')),
path('registration/', RegisterView.as_view(), name='account_signup'),
re_path(r'^account-confirm-email/', VerifyEmailView.as_view(),
     name='account_email_verification_sent'),
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', VerifyEmailView.as_view(),
     name='account_confirm_email'),
re_path(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(),
     name='password_reset_confirm')
]

视图是内置的 rest_auth:

class PasswordResetConfirmView(GenericAPIView):
"""
Password reset e-mail link is confirmed, therefore
this resets the user's password.

Accepts the following POST parameters: token, uid,
    new_password1, new_password2
Returns the success/fail message.
"""
serializer_class = PasswordResetConfirmSerializer
permission_classes = (AllowAny,)

@sensitive_post_parameters_m
def dispatch(self, *args, **kwargs):
    return super(PasswordResetConfirmView, self).dispatch(*args, **kwargs)

def post(self, request):
    serializer = self.get_serializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    serializer.save()
    return Response(
        {"detail": _("Password has been reset with the new password.")}

您的 URLconf 导致 post 方法被调用时带有两个 kwargs – uidb64 和 token – 但您的 post 方法不接受任何 kwargs。要消除错误,只需将 kwargs 添加到 post 方法签名:

def post(self, request, *args, **kwargs):
    # ...