[英]Looking for template in a wrong directory
我已經將Django項目上傳到Openshift,並且python代碼可以正常工作,但是,我的模板是從錯誤的文件夾加載的:
/var/lib/openshift/55b9********************/templates
我的settings.py文件包含:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
正確指向
/var/lib/openshift/55b9********************/app-root/runtime/repo/wsgi/marko/templates
如django的追溯頁面所示。 為什么會這樣呢? 我可以將模板復制到要查找的文件夾中,但我不想將任何項目文件放在項目文件夾之外。 本地計算機上的runserver
在正確的文件夾中查找模板。
您正在運行Django 1.8嗎? TEMPLATE_DIRS
指令已棄用,並由TEMPLATES
代替。
根據文檔,您應該像這樣更新設置:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
假設BASE_DIR/templates
指向正確的目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.