【问题标题】:django email confirmation error: TemplateResponseMixin requires either 'template_name' or 'get_template_names()'django 电子邮件确认错误:TemplateResponseMixin 需要 'template_name' 或 'get_template_names()'
【发布时间】:2019-12-19 08:30:41
【问题描述】:

我有一个带有 customUser 模型(电子邮件/密码)的 django 项目,我正在尝试让电子邮件验证链接正常工作。他们以前一直在工作,但现在由于某种原因,路径失败了。当您在我的网站上注册一个帐户时,您会收到一封包含注册确认 URL 的电子邮件,如下所示:

http://127.0.0.1:8000/rest-auth/registration/account-confirm-email/OA:1hxEiC:mbXKk8-is0YJz2FKHd_1d62KNv8/

但是当你点击这个 url 时,它会导致一个带有消息的错误页面:

ImproperlyConfigured at /rest-auth/registration/account-confirm-email/OA:1hxEiC:mbXKk8-is0YJz2FKHd_1d62KNv8/
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'

我的主 urls.py 文件有一个 urlpatterns 列表,如下所示:

    urlpatterns = [
#admin page
path('admin/', admin.site.urls),
path('playlist/', include(('playlist.urls', 'playlist'), namespace='playlist')),
#users
path('users/', include('django.contrib.auth.urls')),
#accounts (allauth)
path('accounts/', include('allauth.urls')),
...
#django-rest-auth
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
#bug reports for this issue online point to a solution like so, but this isn't fixing the error
url(r"^rest-auth/registration/account-confirm-email/(?P<key>[\s\d\w().+-_',:&]+)/$", allauthemailconfirmation, name="account_confirm_email"),
#jwt
url(r'^refresh-token/', refresh_jwt_token),
]

有人可以帮我找出这个错误吗?我查看了许多其他在线发布的此问题的实例,并发现许多人通过使用正则表达式捕获注册确认路径来解决它,我已经尝试了在网上发布的解决方案中可以找到的所有正则表达式组合,但还没有有幸解决了这个问题。当我点击电子邮件确认链接时,我总是收到同样的错误。

非常感谢任何帮助,谢谢

【问题讨论】:

    标签: django django-templates django-urls django-allauth django-email


    【解决方案1】:

    您似乎认为allauthemailconfirmation 使用了TemplateResponseMixin,这需要定义template_name。你没有。所以在你看来,添加它。类似的东西

    class allauthemailconfirmation(TemplateResponseMixin, whateverClassesDeclared):
        template_name = 'path/to/filename.html'
        ...
    

    【讨论】:

    • 我尝试添加它,但仍然遇到同样的错误,我将主 urls.py 更改为包含“url(r”^rest-auth/registration/account-confirm-email/(?P [\s\d\w().+-_',:&]+)", include('users.urls'), name="account_confirm_email")," 在我的 urls.py 中用户应用添加了 "urlpatterns = [ path('', allauthemailconfirmation.as_view()), ]" ,它转到我的 views.py 文件,其中包含 "class allauthemailconfirmation(TemplateView): template_name = 'pages/home.html'" ,但我仍然收到相同的模板错误
    猜你喜欢
    • 2021-02-07
    • 1970-01-01
    • 2018-04-30
    • 2016-07-02
    • 1970-01-01
    • 2019-04-17
    • 2013-04-23
    • 2017-02-01
    • 1970-01-01
    相关资源
    最近更新 更多