开发服务器上的Django TemplateDoesNotExist存在于生产服务器中 [英] Django TemplateDoesNotExist in production server when it works in development
问题描述
我收到以下错误.只有在生产中,我才能使用apache + mod_wsgi部署Django应用程序.它可以在开发服务器(我的计算机)中正常运行:
I get the following error. It's ONLY IN PRODUCTION where I deploy Django application using apache + mod_wsgi. IT WORKS PERFECTLY IN DEVELOPMENT server(my computer):
TemplateDoesNotExist at /
base.html
验尸.如您所见,仅搜索设置中我的两个文件夹之一:
postmortem. as you can see only one of my two folders from settings are being searched:
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模板位于模板"文件夹中.:
Here are my settings. The base.html template is in "templates" folder.:
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',
],
},
},
]
在这里,我确认此模板确实存在:
Here I confirm that this template actually exists:
>>> from django.template.loader import get_template
>>> get_template("base.html")
<django.template.backends.django.Template object at 0x7f6af68d38d0>
正如您所看到的,在我的模板目录中仅搜索了两个文件夹中的一个,而在开发服务器中,该文件夹运行得很好.任何想法为什么会这样?是否可能是某种权限问题.
As you can see only one folder out of two in my template dirs are being searched while in development server it works just fine. Any ideas why this could be ? Is it possible it's some kind of permissions issue.
推荐答案
在settings.py中为DIRS添加第二个条目为我解决了此问题.
Adding the second entry for DIRS in settings.py fixed this issue for me.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],'
'DIRS': [BASE_DIR + "/templates", ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
这篇关于开发服务器上的Django TemplateDoesNotExist存在于生产服务器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!