Django 共享应用程序中的模板
我有两个django项目,它们共享一些常用的应用程序, 这是我的结构:Django 共享应用程序中的模板,django,django-templates,Django,Django Templates,我有两个django项目,它们共享一些常用的应用程序, 这是我的结构: common_apps app1 templates app1 # default templates for common app live here prj_1 templates app1 # overridden templates for app1 live here (using sam
common_apps
app1
templates
app1
# default templates for common app live here
prj_1
templates
app1
# overridden templates for app1 live here (using same file name)
- prj_1
- prj_2
- 通用应用程序
如何操作?是,使用以下目录结构:
common_apps
app1
templates
app1
# default templates for common app live here
prj_1
templates
app1
# overridden templates for app1 live here (using same file name)
文档中没有在一个地方明确说明这一点,但您的prj_1
模板将覆盖common_apps
,因为在Django中的
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
…您典型的Django设置文件将具有以下内容:
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates'),
# where PROJECT_ROOT is absolute path to prj_1/
)
…这意味着当查找例如'app1/base.html'时,filesystem.Loader
将首先被调用,并将在prj_1
目录中找到任何被覆盖的模板,因此app_目录。不会调用Loader
这里有一些信息: