我正在使用Django-nonrel应用registration。事情似乎工作正常,除非我尝试重置密码。当点击发送给我的重置密码链接时,Django会产生错误消息:
password_reset_confirm() got an unexpected keyword argument 'uidb36'
我的问题:有没有人看过它,知道什么是治愈方法?
修改
问题是由registration \ auth_urls.py引起的 - 它们重复了django \ contrib \ auth \ urls.py中的条目,在Django-nonrel中循环修补了该文件的版本。
任何想法为什么会在那里,我可以实际删除它或修复它吗?
答案 0 :(得分:34)
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>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
以下是详细说明更改的官方更改日志: https://docs.djangoproject.com/en/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk
答案 1 :(得分:9)
我的解决方案是注释掉在registration \ auth_urls.py中定义的urlpatterns,并将它们重新定义为django.contrib.auth中定义的urlpatterns的副本。
这是我在更改后的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'),
)
'''
答案 2 :(得分:5)
我只需将uidb36
参数更改为uidb64
,就像这样:
FROM:
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
TO:
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
然后密码重置再次开始工作。
答案 3 :(得分:1)
我猜你的urls.py中的password_reset_confirm url看起来类似于
URL(R&#39; ^账户/ password_reset /(P [0-9A-ZA-Z] {1,13}) - (P [0-9A-ZA-Z] {1,13}? - [0-9A-ZA-Z] {1,20})/ $&#39 ;, password_reset_confirm, {&#39; post_reset_redirect&#39; :&#39; / accounts / password_reset / complete /&#39;},name =&#34; password_reset_confirm&#34;),
并且您在password_reset_email.html中的链接看起来像 {{protocol}}:// {{domain}} {%url&#39; password_reset_confirm&#39; uidb36 = uid token = token%}
只需将uib36更改为uib64两个地方,它都可以。