Django-nonrel + Django注册问题:重置密码时出现意外的关键字参数\'uidb36\'

问题描述

| 我正在将Django-nonrel与注册应用程序配合使用。除我尝试重设密码外,一切似乎都工作正常。单击电子邮件中发送给我的重置密码链接时,Django会生成错误消息:
password_reset_confirm() got an unexpected keyword argument \'uidb36\'
我的问题:有没有人看到它并且知道治愈的方法? 编辑: 问题是由registration \\ auth_urls.py引起的-它们在django \\ contrib \\ auth \\ urls.py中重复了条目,从而绕过了Django-nonrel中文件的补丁版本。 有什么想法为什么在那儿,我是否可以将其删除或以其他方式解决?     

解决方法

        Django 1.6使用base 64编码作为用户ID,而不是base 36编码。 如果您有任何自定义密码重置URL,则需要通过将uidb36替换为uidb64并在该模式之后的斜线使用斜杠来更新它们。还将\“ _ \”,\“ \\\”和\“-\”添加到可能与uidb64模式匹配的字符列表中。 例如,在Django 1.5-中urls.py中的这一行:
url(r\'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$\',\'django.contrib.auth.views.password_reset_confirm\',name=\'password_reset_confirm\'),
在Django 1.6+中将需要更改为:
url(r\'^reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>.+)/$\',
以下是正式的变更日志,其中详细介绍了变更: https://docs.djangoproject.com/zh-CN/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk     ,        我的解决方案是注释掉registration \\ auth_urls.py中定义的urlpattern,并将它们重新定义为django.contrib.auth中定义的urlpattern的副本。 这是更改后的auth_urls.py:
\"\"\"
URL patterns for the views included in ``django.contrib.auth``.

Including these URLs (via the ``include()`` directive) will set up the
following patterns based at whatever URL prefix they are included
under:

* User login at ``login/``.

* User logout at ``logout/``.

* The two-step password change at ``password/change/`` and
  ``password/change/done/``.

* The four-step password reset at ``password/reset/``,``password/reset/confirm/``,``password/reset/complete/`` and
  ``password/reset/done/``.

The default registration backend already has an ``include()`` for
these URLs,so under the default setup it is not necessary to manually
include these views. Other backends may or may not include them;
consult a specific backend\'s documentation for details.

\"\"\"

from django.conf.urls.defaults import *

#from django.contrib.auth import views as auth_views

from django.contrib.auth import urls as auth_urls

urlpatterns = auth_urls.urlpatterns

\'\'\'
Commented out,this is what caused my problems:

urlpatterns = patterns(\'\',url(r\'^login/$\',auth_views.login,{\'template_name\': \'registration/login.html\'},name=\'auth_login\'),url(r\'^logout/$\',auth_views.logout,{\'template_name\': \'registration/logout.html\'},name=\'auth_logout\'),url(r\'^password/change/$\',auth_views.password_change,name=\'auth_password_change\'),url(r\'^password/change/done/$\',auth_views.password_change_done,name=\'auth_password_change_done\'),url(r\'^password/reset/$\',auth_views.password_reset,name=\'auth_password_reset\'),url(r\'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$\',auth_views.password_reset_confirm,name=\'auth_password_reset_confirm\'),url(r\'^password/reset/complete/$\',auth_views.password_reset_complete,name=\'auth_password_reset_complete\'),url(r\'^password/reset/done/$\',auth_views.password_reset_done,name=\'auth_password_reset_done\'),) 
\'\'\'
    ,        我只需要将
uidb36
参数更改为
uidb64
,就像这样: 从:
url(r\'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$\',
至:
url(r\'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$\',
然后,密码重置再次开始起作用。     ,        我猜您在urls.py中的password_reset_confirm网址看起来类似于 url(r \'^ accounts / password_reset /(?P [0-9A-Za-z] {1,13})-(?P [0-9A-Za-z] {1,13}-[0- 9A-Za-z] {1,20})/ $ \',         password_reset_confirm,         {\'post_reset_redirect \':\'/ accounts / password_reset / complete / \'},name = \“ password_reset_confirm \”), 并且您在password_reset_email.html中的链接看起来像 {{协议}}:// {{域}} {%url \'password_reset_confirm \'uidb36 = uid令牌=令牌%} 只需将uib36更改为uib64,就可以了。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...