Django-rest-auth:未找到 'password_reset_confirm' 的反向。 'password_reset_confirm' 不是有效的视图函数或模式名称
Django-rest-auth: Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name
我正在尝试使用 django-rest-auth 密码重置功能,但在 /rest-auth/password/reset/
的 post 请求后,我收到标题中所述的错误 (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
中添加了所需的应用
我通过添加
解决了
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'),
到 urls.py
中的 urlpatterns。这样您将在邮件中获得重置 link,例如:../password/reset/confirm/uid/token
。为了完成该程序,您必须使用以下正文向 ../password/reset/confirm/
发送 POST 请求:
{
"new_password1": "",
"new_password2": "",
"uid": "",
"token": ""
}
from django.views.generic import TemplateView
urlpatterns += [
path('rest-auth/', include('rest_auth.urls')),
path('rest-auth/registration/', include('rest_auth.registration.urls')),
url(r'^', include('django.contrib.auth.urls')),
url(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})/$',
TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
]
我正在尝试使用 django-rest-auth 密码重置功能,但在 /rest-auth/password/reset/
的 post 请求后,我收到标题中所述的错误 (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
我通过添加
解决了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'),
到 urls.py
中的 urlpatterns。这样您将在邮件中获得重置 link,例如:../password/reset/confirm/uid/token
。为了完成该程序,您必须使用以下正文向 ../password/reset/confirm/
发送 POST 请求:
{
"new_password1": "",
"new_password2": "",
"uid": "",
"token": ""
}
from django.views.generic import TemplateView
urlpatterns += [
path('rest-auth/', include('rest_auth.urls')),
path('rest-auth/registration/', include('rest_auth.registration.urls')),
url(r'^', include('django.contrib.auth.urls')),
url(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})/$',
TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
]