0

我已经在我的Django的10项目目录结构如下:Django的覆盖管理本地工作不生产

/my-project/ # project dir 
    +app1 
    +templates 
     +admin 
      base.html 
     404.html 
     500.html 

我的模板属性看起来像这样的设置:

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [ 
      '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', 
       'common.context_processors.site_info', 
      ], 
     }, 
    }, 
] 

我的定制基。 html显示在我的本地机器上。当我将其上传到我的生产服务器时,它不再覆盖并使用项目文件夹中的base.html文件。

我改变了应用程序的建议顺序here,并尝试打印模板属性的dirs元素,该元素打印“模板/”,如here

有谁知道我可以如何让这个工作在我的生产环境中?

回答

1

您必须在设置中使用绝对路径来避免问题。例如:

import os 

PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..') 
# depending where your settings.py live 

... 
    'DIRS': [ 
     os.path.join(PROJECT_ROOT, 'templates'), 
    ],