为了账号安全,请及时绑定邮箱和手机立即绑定

Django - 未检测到模板

Django - 未检测到模板

qq_笑_17 2021-12-08 16:25:53
我正在使用这个库来处理 django 项目的两个因素身份验证,但我遇到了一些麻烦:在我的站点中,我添加了一个setup.html页面,我在我的urls.py文件中设置了 url,但我不断收到这个错误:In template C:\Users\Us\lib\site-packages\allauth\templates\base.html, error at line 26    Reverse for 'account_email' not found. 'account_email' is not a valid view function or pattern name.    <li><a href="{% url 'account_email' %}">Change E-mail</a></li>这完全很奇怪,因为我不是在尝试加载名为base.html 的文件,而是我自己的setup.html文件,该文件位于我的项目文件夹中(路径是project-folder>templates>setup.html)。这是我想从我自己的模板加载的setup.html:{% extends 'main/header.html' %}{% load i18n %}{% block content %}<h1>  {% trans "Setup Two-Factor Authentication" %}</h1><h4>  {% trans 'Step 1' %}:</h4><p>  {% trans 'Scan the QR code below with a token generator of your choice (for instance Google Authenticator).' %}</p><img src="{{ qr_code_url }}" /><h4>  {% trans 'Step 2' %}:</h4><p>  {% trans 'Input a token generated by the app:' %}</p><form method="post">  {% csrf_token %}  {{ form.non_field_errors }}  {{ form.token.label }}: {{ form.token }}  <button type="submit">    {% trans 'Verify' %}  </button></form>{% endblock %}看起来我正在使用的模块,而不是加载 MY setup.html会加载其他东西,但我找不到解决这个问题的方法。这是我调用来处理设置的视图(它是模块的视图):https : //github.com/percipient/django-allauth-2fa/blob/master/allauth_2fa/views.py这是我自己的urls.py,我提到的视图正在被调用:from django.urls import pathfrom . import viewsfrom django.conf.urls import url, includefrom django.conf.urls import urlfrom allauth_2fa import views as allauth_2fa_viewsapp_name = "main"urlpatterns = [    path("setup/", allauth_2fa_views.TwoFactorSetup.as_view(), name="setup"),    path("", views.homepage, name="homepage"),    path("register/", views.register, name="register"),    path("logout/", views.logout_request, name="logout"),    path("login/", views.login_request, name="login"),]
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

该TwoFactorSetup视图正在使用文件夹allauth_2fa 中的模板setup.html。所以你需要做的就是将你的setup.html放在一个同名的文件夹中:app_folder/templates/allauth_2fa/setup.html来覆盖它。


或者,子类化TwoFactorSetup并更改template_name属性以指向您的模板并在您的urls.py 中使用该视图:


from allauth_2fa.views import TwoFactorSetup


class MySetup(TwoFactorSetup):

    template_name = 'my_app/setup.html'


查看完整回答
反对 回复 2021-12-08
  • 1 回答
  • 0 关注
  • 164 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信