【问题标题】:Reverse for 'account_email_verification_sent' not found. 'account_email_verification_sent' is not a valid view function or pattern name未找到“account_email_verification_sent”的反向。 “account_email_verification_sent”不是有效的视图函数或模式名称
【发布时间】:2018-07-01 15:00:28
【问题描述】:

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

这是我的代码

settings.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


【解决方案1】:

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

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'),    
]
´´´

【讨论】:

    【解决方案2】:

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

    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'),
    
    ]
    

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 2019-04-06
      • 2019-08-13
      • 2019-11-04
      • 2021-04-21
      • 2018-05-20
      • 2021-11-06
      • 2023-04-10
      • 2019-05-19
      相关资源
      最近更新 更多