2012-08-01 95 views
3

当Heroku查找我的html文件时,出现TemplateDoesNotExist错误。这些文件都在开发服务器上同步。该TEMPLATE_DIRS设置为:Heroku找不到Django模板

TEMPLATE_DIRS = ['/Users/jonathanschen/Python/projects/skeleton/myportfolio/templates',] 

但试图加载页面的herokuapp页我收到以下错误时: 我觉得有一些非常基本的,我在这里失踪。

TemplateDoesNotExist at/
index.html 
Request Method: GET 
Request URL: http://morning-coast-2859.herokuapp.com/ 
Django Version: 1.4.1 
Exception Type: TemplateDoesNotExist 
Exception Value:  
index.html 
Exception Location: /app/.heroku/venv/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138 

Template-loader postmortem 

Django tried loading these templates, in this order: 
Using loader django.template.loaders.filesystem.Loader: 
/Users/jonathanschen/Python/projects/skeleton/myportfolio/templates/index.html (File does not exist) 
Using loader django.template.loaders.app_directories.Loader: 
/app/.heroku/venv/lib/python2.7/site-packages/django/contrib/auth/templates/index.html (File does not exist) 
/app/.heroku/venv/lib/python2.7/site-packages/django/contrib/admin/templates/index.html (File does not exist) 

回答

11

你需要更新你的TEMPLATE_DIRS设置为指向的东西的Heroku可以找到 - 你有它设置现在将在本地工作路径,但Heroku的不知道哪里/Users/jonathanschen/是(因为它不没有那个文件夹)。你可能想尝试使你的TEMPLATE_DIRS设置使用相对路径:

import os.path 
PROJECT_DIR = os.path.dirname(__file__) # this is not Django setting. 
TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, "templates"), 
    # here you can add another templates directory if you wish. 
) 

(从http://www.djangofoo.com/35/template_dirs-project-folder

在Django中1.8+,在TEMPLATES而不是改变DIRS选项:

# BASE_DIR should already be in settings 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, "templates")], 
     ... 
    } 
] 
+0

哎girasquid感谢您的回应,我尝试更新设置与您建议的相对路径,但它仍然无法找到模板出于某种原因。 – Jonathan 2012-08-01 22:11:32

+0

它看起来在这里:Django尝试加载这些模板,按以下顺序: 使用loader django.template.loaders.filesystem.Loader: /app/myportfolio/templates/index.html(文件不存在) 使用loader django。 template.loaders.app_directories.Loader: /app/.heroku/venv/lib/python2.7/site-packages/django/contrib/auth/templates/index.html(文件不存在) /app/.heroku /venv/lib/python2.7/site-packages/django/contrib/admin/templates/index.html(文件不存在) – Jonathan 2012-08-01 22:12:01

+0

@girasquad:你可以在本地运行应用程序吗? – Parker 2012-08-01 22:14:54