2017-03-31 58 views
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> 

正如你可以在我的模板迪尔斯只看到一个文件夹出两正在搜索,而在开发服务器,它工作得很好。任何想法,为什么这可能是?这可能是某种权限问题。

+1

Apache将以特殊用户身份运行您的代码。对目录/文件有权限,以便其他用户可以访问它们。 –

+0

@GrahamDumpleton你能举个例子吗? – Marijus

+0

当你运行ls -las/home/bot_frontend/horses/templates/base.html''和''-lasd/home/bot_frontend''时你会得到什么。 –

回答

0

在settings.py中为DIRS添加第二个条目为我解决了这个问题。

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': ['templates'],' 
     'DIRS': [BASE_DIR + "/templates", ], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
相关问题