0
在我的根文件夹中,我有一个模板文件夹,里面有一个base.html文件。我有一个应用程序与一些HTML,我希望它扩展base.html。从项目根Django扩展模板
这里的内部base.html文件的代码:
<header><h3>Header here</h3></header>
{% block content %}
{% endblock %}
<footer><h3>Footer here</h3></footer>
内部应用程序的代码是:
{% extends base.html %}
{% block content %}
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
{% endfor %}
</ul>
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
{% endblock %}
出于某种原因,我在得到一个无效的模板名称“扩展”标签的错误和我不知道为什么。
我从网上搜索更新了我的settings.py文件到这一点,但仍然不能正常工作:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
我已更新模板以包含引号,但现在我得到一个TemplateDoesNotExist错误。我已经将目录包含在DIRS中,如上所示,并且已经检查了base.html位于预期的目录中。有任何想法吗? – dobolicious
@dobolicious检查最新的答案 – Robert
试过了,还是一样的错误@Robert – dobolicious