找不到“account_email_verification_sent”的反向。 “account_email_verification_sent”不是有效的视图函数或模式名称

问题描述 投票:0回答:2

我正在尝试在我的项目中使用 allauth 和 rest-auth,并尝试使用 allauth 中的内置函数来进行电子邮件验证,但这是我得到的:

Link to screenshot of what I get

这是我的代码

设置.py

ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_REQUIRED = True

urls.py

urlpatterns = [
re_path(r'^', include('rest_auth.urls')),
re_path(r'^registration/', include('rest_auth.registration.urls')),
]
django django-rest-framework django-allauth django-rest-auth
2个回答
23
投票

我找到了解决方案,我必须添加一个 URL 才能向后端发出发送请求以发送电子邮件,该 URL 带有正则表达式,其中包含将验证帐户和 URL 的令牌,并添加一个 URL使用名称 account_login 和 URL 登录,使用名称 account_signup 注册,如下所示:

from rest_auth.registration.views import VerifyEmailView, RegisterView


urlpatterns = [
path('', include('rest_auth.urls')),
path('login/', LoginView.as_view(), name='account_login'),
path('registration/', include('rest_auth.registration.urls')),
path('registration/', RegisterView.as_view(), name='account_signup'),
re_path(r'^account-confirm-email/', VerifyEmailView.as_view(),
     name='account_email_verification_sent'),
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', VerifyEmailView.as_view(),
     name='account_confirm_email'),

]

0
投票

我有同样的问题,但我已经设置了电子邮件确认的 URL,但我忘记了名称参数,它是强制性的

from django.conf.urls import url, include

from dj_rest_auth.registration.views import VerifyEmailView

urlpatterns = [
    url('auth/', include('dj_rest_auth.urls')),
    url('auth/registration/', include('dj_rest_auth.registration.urls')),
    url('auth/account-confirm-email/', VerifyEmailView.as_view(), name='account_email_verification_sent'),    
]
´´´
© www.soinside.com 2019 - 2024. All rights reserved.