我正在尝试实现 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'),
]
我得到如下图所示的错误:
最佳答案
您可能需要在标签中指定应用名称:
<a href="{% url 'forum:index' %}">{% trans "Home" %}</a>
关于python - NoReverseMatch 在/论坛/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40469397/