reset_password_complete 处的 NoReverseMatch:Django PasswordResetConfirmView

NoReverseMatch at reset_password_complete: Django PasswordResetConfirmView

我正在使用 Django 的默认密码重置视图和表单向用户发送电子邮件,以便他们通过电子邮件中的 link 重置密码。我已经完成了大部分开发工作,但仍被困在一个问题上。当我收到来自本地主机的电子邮件时,我点击 link,输入我的新密码 2 次,点击 'submit' 并得到这个错误:Error Message.

下面是我的代码。 urls.py


"""defines URL patterns for users"""

from django.urls import path, include, reverse_lazy
from django.contrib.auth import views as auth_views
from . import views
app_name = 'users'

urlpatterns = [
    # include all default auth urls
    path('', include('django.contrib.auth.urls')),
    path('register/', views.register, name='register'),
    path(
        'reset_password/',
        auth_views.PasswordResetView.as_view(
            template_name='registration/password_reset.html',
            success_url=reverse_lazy('users:password_reset_done')
            ) ,
            name='reset_password'
    ),
    path(
        'reset/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(
            template_name='registration/password_reset_form.html',
            success_url=reverse_lazy('users:password_reset_complete')
            ),
            name='password_reset_confirm'
    ),
    path(
        'password_reset_done/',
        auth_views.PasswordResetDoneView.as_view(
            template_name="registration/password_reset_sent.html"),
            name='password_reset_done'
    ),
    path(
        'password_reset_complete/',
        auth_views.PasswordResetCompleteView.as_view(
            template_name='registration/password_reset_done.html'),
            name='password_reset_complete'
    ),
    path('forgot_username/', views.forgot_username, name="forgot_username"),
    path('username_retrieval/', views.username_retrieval, name="username_retrieval"),
]

如您所见,我在 success_url 变量中使用了命名空间 'users',但是,它似乎在 reset_password 路径上起作用,但似乎不起作用在 reset/<uidb64>/<token> 路径上工作。

需要注意的一件事是我的应用程序中有一个自定义用户模型。这会影响我使用此默认 Django 密码重置方法的能力吗?

此外,users/templates/registration/ 文件夹下有我的模板:User App Templates

还有一些事情要提: 当我点击电子邮件中的 link 时,我被定向到 password_reset_confirm 而不是 password_reset_form,这告诉我模板名称也没有被覆盖。

当我改变 success_url=reverse_lazy('users:password_reset_complete')success_url=reverse_lazy('users:password_reset_completed') 该应用程序不会查找 users:password_reset_completed,这意味着 success_url 不会被覆盖。

如有任何帮助,我将不胜感激,如有必要,我可以post编写更多代码并回答问题。

提前致谢!

此行将覆盖您的所有路径:

    path('', include('django.contrib.auth.urls')),

只需删除它,或者如果您想保留其中一些,请将其放在路径的末尾