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

点击我的django网络应用程序上的密码重置链接时收到错误 . 人们之前已经问过这个问题,这里给出了解决方案 - Django-nonrel + Django-registration problem: unexpected keyword argument 'uidb36' when resetting password

在我的情况下,我已经设置为基本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'),
...
)

Pip Freeze

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

回答(2)

2 years ago

如果您使用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'),

2 years ago

这是我的完整urls.py

from django.conf.urls import patterns, include, url, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views

#Use for UNIQUE EMAIL
from registration.backends.default.views import RegistrationView
from registration.forms import RegistrationFormUniqueEmail

from django.contrib import admin
admin.autodiscover()

class RegistrationViewUniqueEmail(RegistrationView):
    form_class = RegistrationFormUniqueEmail


urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'Notes.views.home', name='home'),
    url(r'^profile/edit_profile', 'profiles.views.edit_profile', name='edit_profile'),
    url(r'^profile/(?P<slug>.*)/$', 'profiles.views.profile', name='profile'),             
    url(r'^password/change/$',
                    auth_views.password_change,
                    name='password_change'),
    url(r'^password/change/done/$',
                    auth_views.password_change_done,
                    name='password_change_done'),
    url(r'^password/reset/$',
                    auth_views.password_reset,
                    name='password_reset'),
    url(r'^password/reset/done/$',
                    auth_views.password_reset_done,
                    name='password_reset_done'),
    url(r'^password/reset/complete/$',
                    auth_views.password_reset_complete,
                    name='password_reset_complete'),
    url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
                    auth_views.password_reset_confirm,
                    name='password_reset_confirm'),
    url(r'^register', RegistrationViewUniqueEmail.as_view(),
                    name='registration_form'),
    url(r'^notes/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<slug>.*)/$',
        'Notes.views.note_detail',
        name = "note_detail" ),
    (r'^accounts/', include('registration.backends.default.urls')),
    url(r'^search/', 'Notes.views.search', name='search'),

)

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)