Python Django中TemplateDoesNotExist的模板继承错误
base.html和子html文件位于一个目录app/templates/app中: lead_list.htmlPython Django中TemplateDoesNotExist的模板继承错误,python,django,django-templates,Python,Django,Django Templates,base.html和子html文件位于一个目录app/templates/app中: lead_list.html {% extends "leads/base.html" %} {% block content %} <a href="{% url 'leads:lead-create' %}">Create a new Lead</a> <hr /> <h1>This is a
{% extends "leads/base.html" %}
{% block content %}
<a href="{% url 'leads:lead-create' %}">Create a new Lead</a>
<hr />
<h1>This is all of our leads</h1>
{% for lead in leads %}
<div class="lead">
<a href="{% url 'leads:lead-detail' lead.pk %}">{{ lead.first_name }} {{ lead.last_name }}</a>. Age: {{ lead.age }}
</div>
{% endfor %}
{% endblock %}
设置.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我在django.template.exceptions.TemplateDoesNotExist:lead_list.html中遇到错误
我认为我做的一切都是正确的,并与文档进行了比较,但没有发现我的错误。
提前谢谢 可以使用以下内容渲染模板:
def lead_list(request):
context = {
'leads': Lead.objects.all()
}
return render(request, 'leads/lead_list.html', context)
def lead_列表(请求):
上下文={
“leads”:Lead.objects.all()
}
返回渲染(请求'leads/lead\u list.html',上下文)
APP_DIRS
设置意味着Django将查看应用程序的模板/
目录,但由于没有此类目录直接包含lead_list.html
文件,因此会引发错误。然而,在模板目录中的leads
目录中有这样的模板。你能显示一个存储模板的文件树吗?@WillemVanOnsem我上传了文件树
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
def lead_list(request):
context = {
'leads': Lead.objects.all()
}
return render(request, 'leads/lead_list.html', context)