2012-08-01 14 views
3

HTML 파일을 찾을 때 Heroku에서 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
당신은 Heroku가 찾을 수있는 무언가를 가리 키도록 설정하여 TEMPLATE_DIRS를 업데이트해야합니다

- 당신이 로컬로 작동합니다 지금에 설정 한 경로하지만 아무튼 때문에 Heroku가가 (/Users/jonathanschen/은 아무 생각이 없습니다 해당 폴더가 있음).

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에서)

장고 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을 당신은 상대 경로를 사용 설정하여 TEMPLATE_DIRS을 시도 할 수도 있습니다 응답 주셔서 감사합니다, 당신이 제안한 상대 경로로 설정을 업데이 트했는데 그것은 여전히 ​​캔트 어떤 이유로 템플릿을 찾을 수 없습니다. – Jonathan

+0

Django는 다음 템플릿을이 순서대로로드하려고 시도했습니다. 로더 사용 django.template.loaders.filesystem.Loader : /app/myportfolio/templates/index.html (파일이 존재하지 않습니다) 로더 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

+0

@ girasquad : 앱을 로컬로 실행할 수 있습니까? – Parker

관련 문제