无法重置密码Django 2.1

时间:2018-12-15 13:05:27

标签: django-templates

无法重置django 2.1密码

TypeError: PasswordResetDoneView() received an invalid keyword 'success_url'. as_view only accepts arguments that are al
ready attributes of the class in dhango 2.1

在重定向到重置视图时会显示此错误。     mu urls.py是:     从django.urls导入路径,reverse_lazy     从.import视图     从django.contrib.auth.views导入LoginView,LogoutView,PasswordResetView,PasswordResetDoneView,PasswordResetConfirmView,PasswordResetCompleteView

app_name='account'
urlpatterns = [

   path('',views.home,name='home'),
   path('login/',LoginView.as_view(template_name='account/login.html'),name='login'),
   path('logout/',LogoutView.as_view(template_name='account/logout.html'),name='logout'),
   path('register',views.register),
   path('profile',views.view_profile,name='view_profile'),
   path('profile/edit',views.edit_profile,name='edit_profile'),
   path('change_password',views.change_password,name='change_password'),
   path('password_reset/', PasswordResetView.as_view(template_name='account/reset_password.html',email_template_name='account/reset_password_email.html',success_url = reverse_lazy('password_reset_done')), name='password_reset'),
   path('password_reset/done/',PasswordResetDoneView.as_view(template_name='account/reset_password_done.html',success_url = reverse_lazy('account:password_reset_complete')), name='password_reset_done'),
   path('password_reset/confirm/<uidb64>/<token>/',PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
   path('password_reset/complete/',PasswordResetCompleteView.as_view(), name='password_reset_complete'),
   ]

如何解决?

1 个答案:

答案 0 :(得分:0)

代替此:

path('password_reset/done/',PasswordResetDoneView.as_view(template_name='account/reset_password_done.html',success_url = reverse_lazy('account:password_reset_complete')), name='password_reset_done')

您应该:

success_url放在PasswordResetConfirmView中,因为它将重定向到PasswordResetComplete,如下所示:

path('password_reset/confirm/<uidb64>/<token>/',PasswordResetConfirmView.as_view(success_url = reverse_lazy('account:password_reset_complete'), name='password_reset_confirm')

有关更多信息,请阅读文档: https://docs.djangoproject.com/en/2.2/topics/auth/default/