如何调用header.html
?这是我的文件夹结构。我在/处遇到 TemplateSyntaxError
。
- Project Name - app - home - templates //will contain all the views - home.html - views..py - templates //will contain all the scripts,styles - header.html
Here is my code: Home/templates/home.html
{% extends 'header.html' %}
{% block content %}
<body>
</body>
{% endblock content %}
更新:这是我的Settings.py:
APP_ROOT = os.path.join(BASE_DIR,'apps')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
APP_ROOT + '/home/templates',
APP_ROOT + '/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'
],
},
},
]
最佳答案
根据您项目的目录树,您不需要任何进一步的配置。只需更换
{% extends '../../templates/header.html' %}
由
{% extends 'header.html' %}
然后改变
APP_ROOT + 'home.templates',
由
APP_ROOT + 'home/templates',
关于python - 如何调用应用程序文件夹外的模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54290628/