电子邮件确认错误rest-auth

3

我使用一个标准的表单来发送确认邮件: 从 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')),

]

设置:

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

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

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()'

1
"w+"没有捕获“:”,因此它会回退到dra视图,请将正则表达式更改为新格式。 - mariodev
更改为 account-confirm-email/:(\w+):(?P<key>\w+)/$', - 没有帮助 - Weit
我使用rest-auth的默认模板。 - Weit
我使用以下导入语句:"from allauth.account.views import confirm_email as allauthemailconfirmation" - Weit
无论如何,这个 https://github.com/Tivix/django-rest-auth/issues/20 能帮到你吗? - abidibo
显示剩余2条评论
1个回答

6
我觉得我找到了你的问题。
这个网址:
/rest-auth/registration/account-confirm-email/MTU:1bn1OD:dQ_mCYi6Zpr8h2aKS9J9BvNdDjA/

此模式无法匹配:

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

如果您查看 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'),

因此,您应该重写此视图,否则您将会得到错误,就像这里所解释的那样:https://github.com/Tivix/django-rest-auth/issues/20
您确实尝试过重写视图,但是您的匹配模式是错误的,冒号字符导致它失败,因此让我们尝试类似以下的东西:
url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', allauthemailconfirmation, name="account_confirm_email"), 

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接