python - NoReverseMatch 在/论坛/

标签 python django django-registration

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

关于python - NoReverseMatch 在/论坛/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40469397/

相关文章:

python - python 应用程序和注入(inject)的 DLL 之间的 IPC

python - Django 与 CDN 无缝升级

python - 如何使用 Python 从 zip 文件中去除密码加密

python - 在python中的gstreamer中使用speex的问题

python - 使用正则表达式或常规 Python 进行字符串替换?

django - 统一码编码错误 : 'ascii' codec can't encode character

django - docker文件中PYTHONUNBUFFERED的作用是什么?

django-registration-如何更改电子邮件中的example.com?

python - django-注册 "registery isn' t 准备就绪”错误

python - Django - 身份验证,使用电子邮件确认注册