1
我收到以下錯誤。它只在生產中使用apache + mod_wsgi部署Django應用程序。它工作完全在開發服務器(我的電腦):Django TemplateDoesNotExist生產服務器時,它在開發中
TemplateDoesNotExist at/
base.html
postmortem。你可以看到我的兩個文件夾中只有一個來自設置:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/home/bot_frontend/horses/templates/base.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/base.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/base.html (File does not exist)
/home/virtualenvs/bot_frontend/lib/python2.7/site-packages/django_extensions/templates/base.html (File does not exist)
這是我的設置。該base.html文件模板是「模板」文件夾:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, "templates"),
os.path.join(BASE_DIR, "horses/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',
],
},
},
]
這裏我可以證實,這個模板確實存在:
>>> from django.template.loader import get_template
>>> get_template("base.html")
<django.template.backends.django.Template object at 0x7f6af68d38d0>
正如你可以在我的模板迪爾斯只看到一個文件夾出兩正在搜索,而在開發服務器,它工作得很好。任何想法,爲什麼這可能是?這可能是某種權限問題。
Apache將以特殊用戶身份運行您的代碼。對目錄/文件有權限,以便其他用戶可以訪問它們。 –
@GrahamDumpleton你能舉個例子嗎? – Marijus
當你運行ls -las/home/bot_frontend/horses/templates/base.html''和''-lasd/home/bot_frontend''時你會得到什麼。 –