首页 > 解决方案 > Django-rest-auth:找不到“password_reset_confirm”的反向。'password_reset_confirm' 不是有效的视图函数或模式名称

问题描述

我正在尝试使用 django-rest-auth 密码重置功能,但在发布请求后,/rest-auth/password/reset/我收到标题中所述的错误(Traceback),我不明白为什么。我按照文档页面中的安装过程进行操作。我urls.py的是:

from django.urls import include, path

urlpatterns = [
    path('users/', include('users.urls')),
    path('rest-auth/', include('rest_auth.urls')),
    path('rest-auth/registration/', include('rest_auth.registration.urls')),

我还添加了所需的应用程序settings.py

标签: djangodjango-rest-frameworkdjango-rest-auth

解决方案


我通过添加解决了

from django.urls import include, path, re_path
from rest_auth.views import PasswordResetConfirmView

re_path(r'^rest-auth/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(),
            name='password_reset_confirm'),

到 .url 中的urls.pyurlpatterns 这样,您将在邮件中获得一个重置链接,例如:../password/reset/confirm/uid/token。为了完成该过程,您必须../password/reset/confirm/使用此正文发送 POST 请求:

{
    "new_password1": "",
    "new_password2": "",
    "uid": "",
    "token": ""
}

推荐阅读