问题描述
我的密码重置系统有问题.代码如下.当我直接在浏览器地址中输入相应的URL时,它会显示预期的Django表单/页面.但是,如果我填写电子邮件地址并单击Enter/单击链接,则会得到找不到'password_reset_confirm'的反向字符.'password_reset_confirm'不是有效的视图函数或模式名称."password_reset_email.html中的第6行出现错误.但是我已经包含了uid64!和令牌!另外,当我故意使用错误的电子邮件地址时,会收到找不到'password_reset_done'的反向字符.'password_reset_done'不是有效的视图函数或模式名称."错误.
I am having a problem with the passeord reset system.The code is as below. When I enter the respective URL into the browser address directly it shows the expected Django forms/pages.However if I fill an email address and hit enter/click the link, I get the "Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name." error at line 6 in password_reset_email.html.But I have included the uid64! and the token!Also, when I deliberately use an incorrect email address I get the "Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name." error.
从django文档,该站点上的其他类似问题或各种指南中,我看不到明显的简单步骤是我一定错过了.
I cannot see from the django documentation, other similar questions on this site, or various guides, what the obvious simple step is that I must have missed.
from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
app_name = 'users'
urlpatterns = [
path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('password_reset/confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('password_reset/complete/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
推荐答案
问题是,在反转密码重置urls.py时Django不使用名称空间.您可以通过从 urls.py
中删除 app_name ='users'
来停止错误.
The problem is that Django does not use a namespace when reversing the password reset urls.py. You can stop the error by removing app_name='users'
from your urls.py
.
或者,您可以配置密码重置视图以使用名称空间:"
Alternatively, you can configure the password reset view to use the namespace:"
path('password_reset/', auth_views.PasswordResetView.as_view(success_url=reverse_lazy('users:password_reset_done')), name='password_reset'),
这将解决立即出现的错误,但是您将发现需要进行其他一些更改才能修复类似的错误.删除 app_name ='users'
更为简单.
This will fix the immediate error, but you'll find that you need to make several other changes to fix similar errors. Removing app_name='users'
is more straight forward.
这篇关于Django 2.1.2密码重置身份验证视图:找不到与'password_reset_confirm'相反的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!