电子邮件确认错误rest-auth

Wei*_*eit 0 python django django-rest-framework django-allauth django-rest-auth

我使用标准表格作为确认电子邮件:从allauth.account.views导入Confirm_email作为allauthemailconfirmation

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^rest-auth/', include('rest_auth.urls')),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^rest-auth/registration/account-confirm-email/(?P<key>\w+)/$', allauthemailconfirmation, name="account_confirm_email"),    
    url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),

]
Run Code Online (Sandbox Code Playgroud)

设定:

LOGIN_REDIRECT_URL='/'
ACCOUNT_EMAIL_VERIFICATION='mandatory'
ACCOUNT_CONFIRM_EMAIL_ON_GET=False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = False
Run Code Online (Sandbox Code Playgroud)

我正确地收到了一封电子邮件,但是当您尝试链接时:

ImproperlyConfigured at /rest-auth/registration/account-confirm-email/MTU:1bn1OD:dQ_mCYi6Zpr8h2aKS9J9BvNdDjA/
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'
Run Code Online (Sandbox Code Playgroud)

abi*_*ibo 5

我想我找到了你的问题。

这个网址:

/rest-auth/registration/account-confirm-email/MTU:1bn1OD:dQ_mCYi6Zpr8h2aKS9J9BvNdDjA/
Run Code Online (Sandbox Code Playgroud)

与该模式不匹配:

url(r'^rest-auth/registration/account-confirm-email/(?P<key>\w+)/$', allauthemailconfirmation, name="account_confirm_email"), 
Run Code Online (Sandbox Code Playgroud)

但通过以下方式:

url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
Run Code Online (Sandbox Code Playgroud)

如果您查看的源代码rest_auth.registration.urls,则会看到以下代码:

# This url is used by django-allauth and empty TemplateView is
# defined just to allow reverse() call inside app, for example when email
# with verification link is being sent, then it's required to render email
# content.

# account_confirm_email - You should override this view to handle it in
# your API client somehow and then, send post to /verify-email/ endpoint
# with proper key.
# If you don't want to use API on that step, then just use ConfirmEmailView
# view from:
# django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py#L190
url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(), name='account_confirm_email'),
Run Code Online (Sandbox Code Playgroud)

因此,您应该覆盖此视图,否则将得到您得到的错误,如此处所述:https : //github.com/Tivix/django-rest-auth/issues/20

您确实已经尝试覆盖视图,但是您的匹配模式是错误的,:char导致视图失败,所以让我们尝试类似

url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', allauthemailconfirmation, name="account_confirm_email"), 
Run Code Online (Sandbox Code Playgroud)

相关部分为:(?P [-:\ w] +)/ $