升级Django和NoReverseMatch密码错误

时间:2015-09-17 08:41:36

标签: python django

我正在尝试将旧版本Django 1.5升级到更新版本。 升级后,当我进入密码重置页面时,Django给我错误:

  

/ accounts / password / reset /

中的TypeError      

password_reset()得到了一个意外的关键字参数" post_change_redirect'

     

请求方法:GET   TypeErrorRequest网址:http://localhost:8000/accounts/password/reset/   Django版本:1.6.11   异常类型:TypeError   例外值:

     

password_reseteset()得到了一个意外的关键字参数" post_change_redirect'

     

异常位置:/home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view,第99行   Python可执行文件:/home/martin/Work/wisepress.com/virtualenv/bin/python   Python版本:2.7.8

-

  

回溯:   文件" /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py"在get_response中     112. response = wrapped_callback(request,* callback_args,** callback_kwargs)   文件" /home/martin/Work/wisepress.com/eshopwisepress/wp_auth/views.py"在passwd_reset中     109. return password_reset(request,* args,** kwargs)   文件" /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/utils/decorators.py"在_wrapped_view中     99. response = view_func(request,* args,** kwargs)   文件" /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/contrib/auth/views.py"在password_reset中     142. post_reset_redirect = reverse(' password_reset_done')   文件" /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py"相反     536. return iri_to_uri(resolver._reverse_with_prefix(view,prefix,* args,** kwargs))   文件" /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py"在_reverse_with_prefix中     456.(lookup_view_s,args,kwargs,len(模式),模式))

     

异常类型:NoReverseMatch at / accounts / password / reset /   例外值:反向' password_reset_done'参数'()'和关键字参数' {}'未找到。尝试了0种模式:[]

在urls.py中我有:

      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>[\d\w-]+)/$', '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'),

在views.py中我有:

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)

在Django 1.5中它工作正常,但在较新的版本中给我错误。 你认识任何人如何解决它吗? 感谢

修改 我在urls.py中更改了一些重置密码的网址。现在有:

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

现在我有错误:

  

模板错误:   在模板/home/martin/Work/wisepress.com/eshopwisepress/templates/emailing/registration-activation/password_reset_email.html中,第44行出错

     

&GT;反转&#39; django.contrib.auth.views.password_reset_confirm&#39;参数&#39;()&#39;和关键字参数&#39; {u&#39; uidb64&#39;:&#39;&#39;,你&#39;令牌&#39;:&#39;&#39;}&#39;未找到。尝试了1种模式:[&#39; accounts / password / reset / confirm /(?P \ w +)/(?P [\ d \ w - ] +)/ $&#39;]

第44行现在是:

<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/>

-

  

回溯:   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py"在get_response中     137. response = response.render()   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/response.py"在渲染中     105. self.content = self.rendered_content   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/response.py"在rendered_content中     82. content = template.render(context)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py"在渲染中     140. return self._render(context)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py"在_render     134. return self.nodelist.render(context)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/base.py"在渲染中     840. bit = self.render_node(node,context)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/debug.py"在render_node中     78. return node.render(context)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/defaulttags.py"在渲染中     447. six.reraise(* exc_info)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/template/defaulttags.py"在渲染中     433. url = reverse(view_name,args = args,kwargs = kwargs,current_app = context.current_app)   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py"相反     536. return iri_to_uri(resolver._reverse_with_prefix(view,prefix,* args,** kwargs))   文件&#34; /home/martin/Work/wisepress.com/virtualenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py"在_reverse_with_prefix中     456.(lookup_view_s,args,kwargs,len(模式),模式))

     

异常类型:NoReverseMatch at / accounts / password / reset /   异常值:反转&#39; django.contrib.auth.views.password_reset_confirm&#39;参数&#39;()&#39;和关键字参数&#39; {u&#39; uidb64&#39;:&#39;&#39;,你&#39;令牌&#39;:&#39;&#39;}&#39;未找到。尝试了1种模式:[&#39; accounts / password / reset / confirm /(?P \ w +)/(?P [\ d \ w - ] +)/ $&#39;]

1 个答案:

答案 0 :(得分:0)

password_reset网址格式中,template_name不应与email_template_name相同。 template_name是一个模板,向用户显示密码重置表单。