我的urls.py文件代码:
from django.urls import path
from django.conf.urls import url
from . import views
from django.contrib.auth.views import PasswordResetView,PasswordResetDoneView,PasswordResetConfirmView
app_name = 'user'
urlpatterns = [
url('^login/$',views.user_login,name="user_login"),
url('^logout/$',views.user_logout,name="user_logout"),
url('^password-reset/$',PasswordResetView.as_view(template_name='user/password_reset.html'),name="password_reset"),
url('^password-reset/done/$',PasswordResetDoneView.as_view(template_name='user/password_reset_done.html'),name="password_reset_done"),
url('^password-reset-confirm/<uidb64>/<token>/$',PasswordResetConfirmView.as_view(template_name='user/password_reset_confirm.html'),name="password_reset_confirm"),
url('^home/$',views.register,name="register"),
url('^manage_address/$',views.manage_address,name="manage_address"),
url('^delete_address/(?P<address_id>[0-9]+)/$',views.delete_address,name="delete_address"),
url('^contact_support/$',views.contact_support,name="contact_support"),
]
错误回溯:
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
[25/Feb/2019 23:10:30] "POST /password-reset/ HTTP/1.1" 500 183309
答案 0 :(得分:0)
正在反转password_reset_confirm
的代码不希望您使用命名空间。
最简单的解决方案是删除app_name = 'user'
,或将密码重置URL模式移动到未设置urls.py
的其他app_name
。
如果必须使用名称空间,那么无论您在何处反转URL,都需要更改视图/模板以使用users
名称空间。为了使密码重置过程正常进行,您必须在多个地方执行此操作。