Skip to main content
 首页 » 编程设计

python之Django 在密码重置时得到了一个意外的关键字参数 uidb36

2024年10月25日24cloudgamer

在我的 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

你现在有

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