3

TemplateDoesNotExistHeroku で html ファイルを探すときにエラーが発生します。ファイルはすべて開発サーバーで同期されます。TEMPLATE_DIRS設定は次 のように設定されています。

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)
4

1 に答える 1

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以降では、代わりに次 のDIRSオプションを変更してください。TEMPLATES

# 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")],
        ...
    }
]
于 2012-08-01T21:57:54.737 に答える