django密码重置NoReverseMatch错误

时间:2016-03-02 11:17:11

标签: python django passwords reset

我正在开发一个Django应用,但我在设置重置密码方面遇到了麻烦。我收到以下错误:

  

反向' password_reset_confirm'参数'()'和关键字   争论' {u' uidb64':' MQ',u'令牌':u' 49v-cabad3fe98f5d9f64377'}'   未找到。尝试了0种模式:

这是我的password_reset_email.html文件,它是:

Someone asked for password reset for email {{ email }}. Follow the link below:
{{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

我在urls.py中有以下内容

(r'^registration/password_reset_confirm', 'django.contrib.auth.views.password_reset_confirm',
    {'template_name' : 'coursework/password_reset_confirm.html',
     'set_password_form' : SetPasswordForm,
     'post_reset_redirect' : 'coursework.views.list_comments'}),
(r'^registration/password_reset_done', 'django.contrib.auth.views.password_reset_done',
    {'template_name' : 'coursework/index.html'}),
(r'^registration/password_reset', 'django.contrib.auth.views.password_reset',
    {'password_reset_form' : PasswordResetForm,
     'template_name' : 'coursework/reset_password.html',
     'email_template_name' : 'coursework/password_reset_email.html',
     'subject_template_name' :'coursework/password_reset_subject.txt',
     'post_reset_redirect' : 'coursework.views.list_comments'}),

显然,我做了一些愚蠢的事情,但我无法解决这个问题。

添加堆栈追踪

Environment:


Request Method: POST
Request URL: http://localhost:23080/registration/password_reset

Django Version: 1.9
Python Version: 2.7.11
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'coursework')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "C:\FCA\lib\django\core\handlers\base.py" in get_response
  134.                 resolver_match = resolver.resolve(request.path_info)

File "C:\FCA\lib\django\core\urlresolvers.py" in resolve
  374.             for pattern in self.url_patterns:

File "C:\FCA\lib\django\utils\functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "C:\FCA\lib\django\core\urlresolvers.py" in url_patterns
  417.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "C:\FCA\lib\django\utils\functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "C:\FCA\lib\django\core\urlresolvers.py" in urlconf_module
  410.             return import_module(self.urlconf_name)

File "C:\Python27\lib\importlib\__init__.py" in import_module
  37.     __import__(name)

Exception Type: SyntaxError at /registration/password_reset
Exception Value: invalid syntax (urls.py, line 24)

2 个答案:

答案 0 :(得分:5)

我发布此答案可能会帮助其他人解决同样的问题。 我得到了同样的错误并在互联网上做了所有建议的解决方案,没有运气!

最后,感谢link的帮助,它有效!

解决方案:url(r'^', include('django.contrib.auth.urls')),添加到mainProject>urls.py

答案 1 :(得分:2)

您的模式不接受uidb64token个参数。将其更改为:

(r'^registration/password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm',
 {'template_name' : 'coursework/password_reset_confirm.html',
  'set_password_form' : SetPasswordForm,
  'post_reset_redirect' : 'coursework.views.list_comments'},
 name='password_reset_confirm'),