本文介绍了电子邮件密码重置系统出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建用于使用电子邮件重设密码的系统时遇到了麻烦.我昨天遇到一个无法解决的问题:密码重置电子邮件出现NoReverseMatch错误

I have been having trouble creating a system for resetting passwords using email. I encountered a problem yesterday which I was unable to solve:NoReverseMatch error with password reset emails

在阅读了一些相关文档之后,我尝试将视图替换为1.11中引入的基于类的等效项,如下所示:

After reading some of the relevant docs, I tried to replace the views with the class-based equivalents introduced in 1.11 as below:

urls.py:

from django.contrib.auth import views as auth_views

urlpatterns = [
    url(r'^$', auth_views.login, name='login'),
    url(r'^logout/$', auth_views.logout, name='logout'),

    ## more irrelevant urls here ##
    url(r'^password/reset/done/$', auth_views.PasswordResetDoneView, name='password_reset_done'),
    url(r'^password/reset/$', auth_views.PasswordResetView, name='password_reset'),
    url(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.PasswordResetConfirmView, name='password_reset_confirm'),
    url(r'^password/reset/complete/$', auth_views.PasswordResetCompleteView, name='password_reset_complete'),
]

这引入了一个新的错误,它不是很有帮助:

This has introduced a new error which is not very helpful:

Internal Server Error: /password/reset/
Traceback (most recent call last):
  File "C:\python\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
    response = get_response(request)
  File "C:\python\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\python\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
[11/Feb/2018 12:35:38] "GET /password/reset/ HTTP/1.1" 500 62168

如何使我的系统正常工作?

How can I get my system working?

推荐答案

您需要致电 as_view 用于url.py中基于类的视图的方法:

You need to call as_view method for class based view in url.py:

url(r'^password/reset/done/$', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
url(r'^password/reset/$', auth_views.PasswordResetView.as_view(), name='password_reset'),
url(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
url(r'^password/reset/complete/$', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),

这篇关于电子邮件密码重置系统出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:29