我正在尝试在我的项目中使用 allauth 和 rest-auth,并尝试使用 allauth 中的内置函数来进行电子邮件验证,但这是我得到的:
这是我的代码
设置.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')),
]
我找到了解决方案,我必须添加一个 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'),
]
我有同样的问题,但我已经设置了电子邮件确认的 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'),
]
´´´