Django - 未检测到模板

我正在使用这个库来处理 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 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"),


]


qq_笑_17
浏览 165回答 1
1回答

慕码人8056858

该TwoFactorSetup视图正在使用文件夹allauth_2fa 中的模板setup.html。所以你需要做的就是将你的setup.html放在一个同名的文件夹中:app_folder/templates/allauth_2fa/setup.html来覆盖它。或者,子类化TwoFactorSetup并更改template_name属性以指向您的模板并在您的urls.py 中使用该视图:from allauth_2fa.views import TwoFactorSetupclass MySetup(TwoFactorSetup):&nbsp; &nbsp; template_name = 'my_app/setup.html'
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python