Skip to main content
 首页 » 编程设计

python之NoReverseMatch 在/论坛/

2025年04月02日9飞鱼

我正在尝试实现 django-registration-redux 并使用了由 Andres 编写的模板,网址为 https://github.com/macdhuibh/django-registration-templates .但问题是无论我运行什么,我都会收到 NoReverseMatch 错误。

我尝试渲染 base.html 模板来检查错误,但在第 12 行出现错误。

base.html 是

{% load i18n %} 
<html lang="en"> 
 
<head> 
    <link rel="stylesheet" href="{{ STATIC_URL }}style.css" /> 
    <title>{% block title %}User test{% endblock %}</title> 
</head> 
 
<body> 
    <div id="header"> 
    {% block header %} 
    <a href="{% url 'index' %}">{% trans "Home" %}</a> | 
 
    {% if user.is_authenticated %} 
        {% trans "Logged in" %}: {{ user.username }}  
        (<a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a> |  
        <a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a>) 
    {% else %} 
       <a href="{% url 'auth_login' %}">{% trans "Log in" %}</a> 
    {% endif %} 
    <hr /> 
    {% endblock %} 
    </div> 
 
<div id="content"> 
{% block content %}{% endblock %} 
</div> 
 
<div id="footer"> 
{% block footer %} 
    <hr /> 
{% endblock %} 
</div> 
</body> 
 
</html> 

index.html 是

{% extends "base.html" %} 
{% load i18n %} 
 
{% block content %} 
Index page 
{% endblock %} 

和 urls.py 作为

from django.conf.urls import url 
from . import views 
 
app_name = 'forum' 
urlpatterns = [ 
 
    url(r'^$', views.index, name='index'), 
 
] 

我得到如下图所示的错误:

Error

请您参考如下方法:

您可能需要在标签中指定应用名称:

<a href="{% url 'forum:index' %}">{% trans "Home" %}</a>