单击django网络应用程序上的密码重置链接时出现错误。人们之前曾问过这个问题,解决方案在这里给出-Django-nonrel + Django-registration problem: unexpected keyword argument 'uidb36' when resetting password

就我而言,我已经将其设置为base 64编码(请参见下面的urls.py),但仍然收到此错误消息。

错误

password_reset_confirm() got an unexpected keyword argument 'uidb36'


追溯

Traceback:
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  75.             return view(request, *args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)

Exception Type: TypeError at /accounts/password/reset/confirm/Mg-3ve-2379945fbf21a5bfbe8c/
Exception Value: password_reset_confirm() got an unexpected keyword argument 'uidb36'


在我的urls.py中

urlpatterns = patterns('',
...
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
                    auth_views.password_reset_confirm,
                    name='password_reset_confirm'),
...
)


点冻结

Django==1.6.6
South==1.0
dj-database-url==0.3.0
django-admin-bootstrapped==2.0.4
django-autoslug==1.7.2
django-crispy-forms==1.4.0
django-endless-pagination==2.0
django-guardian==1.2.4
django-registration==1.0
pytz==2014.7
six==1.8.0
wsgiref==0.1.2

最佳答案

如果您使用的是Django 1.6或更高版本,则您使用的代码是错误的,因为在Django 1.6中更改了密码重置。

请在这里阅读https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.views.password_reset

您必须相应地更改密码重置电子邮件的模板。

您还必须相应地更改网址

你现在有

url(r'^password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm',
 {'post_reset_redirect' : '/accounts/password/done/'}),


应该是这样的

url(r'^reset/(?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',
    name='password_reset_confirm'),

10-05 20:44
查看更多