简体   繁体   English

Heroku找不到Django模板

[英]Heroku can't find Django templates

I'm getting a TemplateDoesNotExist error on Heroku when it looks for my html files. 我在Heroku上查找我的html文件时遇到TemplateDoesNotExist错误。 The files all sync up on the development server. 这些文件都在开发服务器上同步。 The TEMPLATE_DIRS setting is set to: TEMPLATE_DIRS设置设置为:

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

But when trying to load the page the herokuapp page I get the following error: I think there's something very basic I'm missing here. 但是当我尝试加载页面时,我发现了以下错误:我认为这里有一些非常基本的东西。

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)

You'll need to update your TEMPLATE_DIRS setting to point to something Heroku can find - the path that you have it set to right now will work locally, but Heroku has no idea where /Users/jonathanschen/ is (because it doesn't have that folder). 您需要更新您的TEMPLATE_DIRS设置以指向Heroku可以找到的东西 - 您现在设置的路径将在本地工作,但Heroku不知道/Users/jonathanschen/在哪里(因为它没有那个文件夹)。 You might want to try making your TEMPLATE_DIRS setting use a relative path: 您可能想尝试使用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.
)

(from http://www.djangofoo.com/35/template_dirs-project-folder ) (来自http://www.djangofoo.com/35/template_dirs-project-folder

In Django 1.8+, change the DIRS option in TEMPLATES instead: 在Django 1.8+中,更改TEMPLATESDIRS选项:

# 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")],
        ...
    }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM