Django密码重置没有反向匹配
Posted
技术标签:
【中文标题】Django密码重置没有反向匹配【英文标题】:Django Password Reset No reverse match 【发布时间】:2018-12-03 17:19:30 【问题描述】:我正在尝试使用 django 的密码重置
输入邮箱重置密码后出现以下错误
django.urls.exceptions.NoReverseMatch: 反向 未找到“密码重置确认”。 'password_reset_confirm' 不是 有效的视图函数或模式名称。
我的 urls.py 包括
path(
"dashboard/",
include(("ami.dashboard.urls", "dashboard"), namespace="dashboard"),
),
我的仪表板/urls.py 是
from django.conf.urls import include, url
# from graphene_django.views import GraphQLView
# from django.contrib import admin
from django.contrib.auth import views as auth_views
from . import views as core_views
from .product.urls import urlpatterns as product_urls
urlpatterns = [
url(r'^$', core_views.index, name='index'),
url(r'^products/', include(product_urls)),
# url(r'^login/$', auth_views.login, name='login'),
url(r'^login/$', auth_views.login, 'template_name': 'dashboard/login.html', name='login'),
url(r'^logout/$', auth_views.logout, 'next_page': '/', name='logout'),
# url(r'^logout/$', auth_views.logout, name='logout'),
# url(r'^admin/', admin.site.urls),
url(r'^', include('django.contrib.auth.urls')),
url(r'^password_reset/$', auth_views.password_reset,
'post_reset_redirect': '/dashboard/password_reset/done/'
, 'template_name': 'registration/password_reset_form.html',
name='password_reset'),
url(r'^password_reset/done/$', auth_views.password_reset_done,
'template_name': 'registration/password_reset_done.html', name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]1,13-[0-9A-Za-z]1,20)/$',
auth_views.password_reset_confirm, 'template_name': 'registration/password_reset_confirm.html',
name='password_reset_confirm'),
url(r'^reset/done/$', auth_views.password_reset_complete,
'template_name': 'registration/password_reset_complete.html',
name='password_reset_complete'),
]
错误回溯:
文件 “/usr/local/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py”, 第 66 行,在 call
中return self.application(environ, start_response)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/wsgi.py", 第 146 行,在 call
中response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", 第 81 行,在 get_response 中
response = self._middleware_chain(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 “/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py”, 第 95 行,在 调用
response = self.get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 37 行,在内部
response = response_for_exception(request, exc)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 87 行,在 response_for_exception 中
响应 = handle_uncaught_exception(请求, get_resolver(get_urlconf()), sys.exc_info())
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 122 行,在 handle_uncaught_exception 中
返回 debug.technical_500_response(request, *exc_info)
文件 “/usr/local/lib/python3.6/site-packages/django_extensions/management/technical_response.py”,第 6 行,在 null_technical_500_response
six.reraise(exc_type, exc_value, tb)
文件“/usr/local/lib/python3.6/site-packages/six.py”,第 693 行,在 再加注
提升价值
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 第 35 行,在内部
response = get_response(request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", 第 128 行,在 _get_response 中
response = self.process_exception_by_middleware(e, request)
文件 "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", 第 126 行,在 _get_response 中
response = Wrapped_callback(request, *callback_args, **callback_kwargs)
文件“/usr/local/lib/python3.6/contextlib.py”,第 52 行,在内部
返回函数(*args, **kwds)
文件 “/usr/local/lib/python3.6/site-packages/django/views/generic/base.py”, 第 69 行,可见
return self.dispatch(request, *args, **kwargs)
文件 "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", 第 62 行,在 _wrapper 中
return bound_func(*args, **kwargs)
文件 "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", 第 142 行,在 _wrapped_view 中
response = view_func(request, *args, **kwargs)
文件 "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", 第 58 行,在 bound_func 中
返回函数。get(self, type(self))(*args2, **kwargs2)
文件 “/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py”, 第 407 行,正在调度中
return super().dispatch(*args, **kwargs)
文件 “/usr/local/lib/python3.6/site-packages/django/views/generic/base.py”, 第 89 行,正在调度中
返回处理程序(请求,*args,**kwargs)
文件 “/usr/local/lib/python3.6/site-packages/django/views/generic/edit.py”, 第 142 行,在帖子中
返回 self.form_valid(form)
文件 “/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py”, 第 420 行,在 form_valid 中
form.save(**opts)
文件 “/usr/local/lib/python3.6/site-packages/django/contrib/auth/forms.py”, 第 297 行,保存中
电子邮件,html_email_template_name=html_email_template_name,
文件 “/usr/local/lib/python3.6/site-packages/django/contrib/auth/forms.py”, 第 244 行,在 send_mail 中
body = loader.render_to_string(email_template_name, context)
文件 "/usr/local/lib/python3.6/site-packages/django/template/loader.py", 第 62 行,在 render_to_string 中
return template.render(context, request)
文件 "/usr/local/lib/python3.6/site-packages/django/template/backends/django.py", 第 61 行,在渲染中
返回 self.template.render(context)
文件“/usr/local/lib/python3.6/site-packages/django/template/base.py”, 第 175 行,在渲染中
返回 self._render(context)
文件“/usr/local/lib/python3.6/site-packages/django/test/utils.py”, 第 98 行,在 Instrumented_test_render 中
返回 self.nodelist.render(context)
文件“/usr/local/lib/python3.6/site-packages/django/template/base.py”, 第 943 行,在渲染中
bit = node.render_annotated(context)
文件“/usr/local/lib/python3.6/site-packages/django/template/base.py”, 第 910 行,在 render_annotated 中
返回 self.render(context)
文件 "/usr/local/lib/python3.6/site-packages/django/template/defaulttags.py", 第 37 行,在渲染中
输出 = self.nodelist.render(context)
文件“/usr/local/lib/python3.6/site-packages/django/template/base.py”, 第 943 行,在渲染中
bit = node.render_annotated(context)
文件“/usr/local/lib/python3.6/site-packages/django/template/base.py”, 第 910 行,在 render_annotated 中
返回 self.render(context)
文件 "/usr/local/lib/python3.6/site-packages/django/template/defaulttags.py", 第 447 行,在渲染中
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
文件“/usr/local/lib/python3.6/site-packages/django/urls/base.py”, 第 88 行,反方向
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
文件 "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", 第 632 行,在 _reverse_with_prefix 中
【问题讨论】:
使用回溯发布整个错误消息。还要发布您的主要 urls.py 和导致异常的模板。 @Selcuk 这有帮助吗?? 什么时候出现这个错误? @seuling:在我输入用于发送密码重置链接的电子邮件后发生 我认为@kristaps 写了正确的答案 【参考方案1】:您正在为要包含的 URL 指定命名空间 - “仪表板”:
include(("ami.dashboard.urls", "dashboard"), namespace="dashboard"),
在这种情况下,您需要在反转 URL 时包含命名空间,请尝试:
reverse('dashboard:password_reset_confirm')
在您将使用的模板中:
% url 'dashboard:password_reset_confirm' %
Django 文档中的更多信息:Reversing namespaced URLs
【讨论】:
谢谢我在我的模板中使用了 % url 'password_reset_confirm' %以上是关于Django密码重置没有反向匹配的主要内容,如果未能解决你的问题,请参考以下文章
Django 2.1.2 密码重置身份验证视图:找不到“password_reset_confirm”的反向
在使用 Django 框架构建的博客 Web 应用程序中单击重置密码时,我没有收到密码重置电子邮件链接