无法重置密码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.url的导入路径,reverse_lazy来自.import视图从django.contrib.auth.views导入LoginView、LogoutView、PasswordResetView、PasswordResetDoneView、PasswordReset ConfirmView、Password ResetCompleteView
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'),
]
如何解决?
而不是:
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/