Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 共享应用程序中的模板_Django_Django Templates - Fatal编程技术网

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

我有两个django项目,它们共享一些常用的应用程序, 这是我的结构:

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
  • 通用应用程序
从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

这里有一些信息: