我正在尝试使用django模板标签从基本模板链接到网站中的应用程序-但是它一直在寻找错误的应用程序,我不知道为什么。
这是我的基本html文件的代码:
<!DOCTYPE html>
<html>
<head>
<title>kinbank</title>
{% block head %}{% endblock %}
</head>
<body>
<div>
<div class="page-width">
<h1 class="top-org-name">
</h1>
<div class="nav">
<a href="{% url 'home:index' %}">Home</a>
<a href="{% url 'languages:index' %}">Languages</a>
</div>
<div class="clear">
</div>
</div>
</div>
{% block content %}{% endblock %}
</body>
和基本网址文件
urlpatterns = [
path('languages/', include('languages.urls')),
path('home/', include('home.urls')),
path('admin/', admin.site.urls),
]
奇怪的是,主页链接有效,而语言链接无效。
我得到的错误是:
TemplateSyntaxError at /home/
但是此行中发生错误
<a href="{% url 'languages:index' %}">Languages</a>
这是回溯:
Traceback:
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/sp16194/Desktop/Projects_Git/kinbank3/kinbank/home/views.py" in index
18. return HttpResponse(template.render(context, request))
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in render
171. return self._render(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/loader_tags.py" in render
127. compiled_parent = self.get_parent(context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/loader_tags.py" in get_parent
124. return self.find_template(parent, context)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/loader_tags.py" in find_template
104. template_name, skip=history,
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/engine.py" in find_template
126. template = loader.get_template(name, skip=skip)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/loaders/base.py" in get_template
30. contents, origin, origin.template_name, self.engine,
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in __init__
156. self.nodelist = self.compile_nodelist()
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in compile_nodelist
194. return parser.parse()
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in parse
478. raise self.error(token, e)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in parse
476. compiled_result = compile_func(self, token)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/defaulttags.py" in url
1375. args.append(parser.compile_filter(value))
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in compile_filter
563. return FilterExpression(token, self)
File "/Users/sp16194/.local/lib/python3.5/site-packages/django/template/base.py" in __init__
663. "from '%s'" % (token[upto:], token))
Exception Type: TemplateSyntaxError at /home/
Exception Value: Could not parse the remainder: '=' from '='
答案 0 :(得分:2)
在您语言应用的 urls.py 中设置应用名称,如下所示
app_name = languages