我有一个包含 2 个应用程序的项目
project/
blog/
templates/
index.html
polls/
templates/
index.html
project/
templates/
base.html
index.html
现在我希望这两个应用程序扩展项目
base.html
.这是要走的路吗?这怎么可能,是否有更好的解决方案?已经有一个问题正在处理这个问题,但只有在您不使用拆分目录时才值得一提:
Django project base template
tl; dr:我想使用拆分目录并想知道如何从多个应用程序扩展基本模板而不将其复制到每个应用程序
最佳答案
在当前的 Django (1.10) TEMPLATE_DIRS is deprecated , 所以:
templates
项目根目录下的目录,TEMPLATES = [
{
...
'DIRS': [(os.path.join(BASE_DIR, 'templates')),],
...
}
{% extends 'base.html' %}
将其扩展到您想要的任何位置关于django - Django 中所有应用程序的基本模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29492617/