gpt4 book ai didi

python - 密码重置 Django 1.6

转载 作者:行者123 更新时间:2023-11-30 23:22:24 25 4
gpt4 key购买 nike

我刚刚将我的 django 安装从旧版本更新到 1.6。

我的 urls.py 文件包含以下内容:

url(r'^user/password/$','django.contrib.auth.views.password_change',name='password_change'),
url(r'^user/password/done/$','django.contrib.auth.views.password_change_done',name='password_change_done'),
url(r'^user/password/reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
url(r'^user/password/password/reset/done/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
url(r'^user/password/reset/complete/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete'),
#url(r'^user/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'),
url(r'^user/password/reset/confirm/(?P<uidb36>[0-9A-Za-z_\-]+)/(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm_uidb36', name='password_reset_confirm'),

一直尝试允许用户重置密码,但是在提交电子邮件地址时出现以下错误:

NoReverseMatch: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'xxxxx', u'token': u'xxxxxxxxxxxxx'}' not found. 0 pattern(s) tried: []

(问题的 x 已更改)

django.contrib.auth.views.password_reset_confirm def 在这里:

# Doesn't need csrf_protect since no-one can guess the URL
@sensitive_post_parameters()
@never_cache
def password_reset_confirm(request, uidb64=None, token=None,
template_name='registration/password_reset_confirm.html',
token_generator=default_token_generator,
set_password_form=SetPasswordForm,
post_reset_redirect=None,
current_app=None, extra_context=None):
"""
View that checks the hash in a password reset link and presents a
form for entering a new password.
"""
UserModel = get_user_model()
assert uidb64 is not None and token is not None # checked by URLconf
if post_reset_redirect is None:
post_reset_redirect = reverse('password_reset_complete')
else:
post_reset_redirect = resolve_url(post_reset_redirect)
try:
uid = urlsafe_base64_decode(uidb64)
user = UserModel._default_manager.get(pk=uid)
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
user = None

if user is not None and token_generator.check_token(user, token):
validlink = True
if request.method == 'POST':
form = set_password_form(user, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(post_reset_redirect)
else:
form = set_password_form(None)
else:
validlink = False
form = None
context = {
'form': form,
'validlink': validlink,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context,
current_app=current_app)

当使用注释的 url 而不是其下面的 url 时,会出现以下错误:

NoReverseMatch: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'xxxxx', u'token': u'xxxxxxxxxxxxxx'}' not found. 1 pattern(s) tried: ['user/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>.+)/$']

最佳答案

View 的第一个关键字参数名称是 uidb64,但您在关键字参数字典中传递 uidb36。更改您的 URL 模式并使用带注释的版本。 1.6 版本中方法签名发生了变化。

再次查看您的错误消息,我认为这不是您的 URL 配置中的问题,而是您使用反向 URL 解析的 View 或模板中的问题。这是 django.core.urlresolvers.reverse 方法或 url 模板标记。您可能正在传递一个带有键 uidb36 的关键字参数,需要将其更改为 uidb64

关于python - 密码重置 Django 1.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24509297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com