简体   繁体   English

电子邮件密码重置系统出错

[英]Error with system for email password resets

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 昨天遇到一个无法解决的问题: 密码重置电子邮件出现NoReverseMatch错误

After reading some of the relevant docs, I tried to replace the views with the class-based equivalents introduced in 1.11 as below: 阅读了一些相关文档后,我尝试用1.11中引入的基于类的等效项替换视图,如下所示:

urls.py: 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? 如何使我的系统正常工作?

You need to call as_view method for class based view in url.py: 您需要在url.py中为基于类的视图调用as_view方法:

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'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM