Upgrade Django and NoReverseMatch password Error
I am trying upgrade old version Django 1.5 to newer. And after upgrade when I go to password reset page, Django give me Error:
TypeError at /accounts/password/reset/
password_reset() got an unexpected keyword argument 'post_change_redirect'
Request Method: GET TypeErrorRequest URL: http://localhost:8000/accounts/password/reset/ Django Version: 1.6.11 Exception Type: TypeError Exception Value:
password_reseteset() got an unexpected keyword argument 'post_change_redirect'
Exception Location: /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view, line 99 Python Executable: /home/martin/Work/wisepress.com/virtualenv/bin/python Python Version: 2.7.8
--
Traceback: File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 112. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/martin/Work/wisepress.com/eshopwisepress/wp_auth/views.py" in passwd_reset 109. return password_reset(request, *args, **kwargs) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in password_reset 142. post_reset_redirect = reverse('password_reset_done') File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse 536. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2. 7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 456. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /accounts/password/reset/ Exception Value: Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
In urls.py I have:
url(r'^password/reset/done/$', 'django.contrib.auth.views.password_reset_done', name='passwd_reset_done'),
url(r'^password/reset/confirm/(?P<uidb36>w+)/(?P<token>[dw-]+)/$', 'django.contrib.auth.views.password_reset_confirm_uidb36', name='passwd_reset_confirm'),
url(r'^password/reset/completed/$', 'django.contrib.auth.views.password_reset_complete', name='passwd_reset_complete'),
url(r'^password/reset/$', passwd_reset, {'template_name':'emailing/registration-activation/password_reset_email.html'}, name='password_reset'),
And in views.py I have:
from django.contrib.auth.views import password_reset
def passwd_reset(request, *args, **kwargs):
kwargs['password_reset_form'] = PasswdResetForm
kwargs['email_template_name'] = 'emailing/registration-activation/password_reset_email.html'
kwargs['from_email'] = FROM_EMAIL
return password_reset(request, *args, **kwargs)
In Django 1.5 it works fine, but in newer versions give me the Error. Do you know anybody how to fix it?? Thanks
EDIT: I changed in urls.py some urls for reset password. Now is there:
url(r'^password/reset/done/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_-]+)/(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'),
url(r'^password/reset/completed/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete'),
url(r'^password/reset/$', passwd_reset, {'template_name':'emailing/registration-activation/password_reset_email.html'}, name='password_reset'),
And now I have Error:
Template error: In template /home/martin/Work/wisepress.com/eshopwisepress/templates/emailing/registration-activation/password_reset_email.html, error at line 44
> Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': '', u'token': ''}' not found. 1 pattern(s) tried: ['accounts/password/reset/confirm/(?Pw+)/(?P[dw-]+)/$']
On line 44 is now:
<a href="{{ protocol }}://{{ site_name }} {% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %} " target="_blank" style="color: #68b58e; text-decoration: none; font-style: italic;">Reset password</a><br/><br/>
--
Traceback: File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 137. response = response.render() File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/response.py" in render 105. self.content = self.rendered_content File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content 82. content = template.render(context) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py" in render 140. return self._render(context) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) File "/home/marti n/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. return node.render(context) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 447. six.reraise(*exc_info) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 433. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse 536. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File "/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 456. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /accounts/password/reset/ Exception Value: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': '', u'token': ''}' not found. 1 pattern(s) tried: ['accounts/password/reset/confirm/(?Pw+)/(?P[dw-]+)/$']
In your password_reset
url pattern, the template_name
should not be the same as your email_template_name
. The template_name
is a template that shows the password reset form to the user.
上一篇: 如何使用django项目上传csv文件