Django - 未检测到模板

Django - template not being detected

我正在使用 this library 来处理 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 %}

看起来我正在使用的模块,而不是加载我的 setup.html 会加载其他东西,但我找不到修复的方法这个。

这是我调用来处理设置的视图(它是模块的视图): https://github.com/percipient/django-allauth-2fa/blob/master/allauth_2fa/views.py

这是我自己的 urls.py,我提到的视图被称为:

from django.urls import path
from . import views
from django.conf.urls import url, include

from django.conf.urls import url

from allauth_2fa import views as allauth_2fa_views
app_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"),

]

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'