【问题标题】:NoReverseMatch at /forum//forum/ 上的 NoReverseMatch
【发布时间】:2016-11-07 16:01:21
【问题描述】:

我正在尝试实现 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

【问题讨论】:

    标签: python django django-registration


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多