Python 赫罗库可以';找不到Django模板
Heroku在查找html文件时出现Python 赫罗库可以';找不到Django模板,python,django,heroku,Python,Django,Heroku,Heroku在查找html文件时出现TemplateDoesNotExist错误。所有文件都在开发服务器上同步。TEMPLATE\u DIRS设置设置为: TEMPLATE_DIRS = ['/Users/jonathanschen/Python/projects/skeleton/myportfolio/templates',] 但是,当尝试将页面加载到herokuapp页面时,出现以下错误: 我想我这里缺少了一些非常基本的东西 TemplateDoesNotExist at / index
TemplateDoesNotExist
错误。所有文件都在开发服务器上同步。TEMPLATE\u 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)
您需要更新模板的DIRS设置,以指向Heroku可以找到的内容-您现在设置的路径将在本地工作,但Heroku不知道
/Users/jonathanschen/
在哪里(因为它没有该文件夹)。您可能希望尝试使用相对路径设置模板\u 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.
)
(来自)
在Django 1.8+中,更改模板
中的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")],
...
}
]
嘿,girasquid感谢您的响应,我尝试使用您建议的相对路径更新设置,但由于某些原因,它仍然找不到模板。这里显示: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(文件不存在)@girasquad:你能在本地运行应用程序吗?谢谢@gira我把templates文件夹放在根目录下,而不是应用程序内部directory@Jonathan我现在有这个问题。我有
importos
BASE\u DIR=os.path.dirname(os.path.dirname(\uu文件\uuu))
TEMPLATE\u DIRS=(os.path.join(os.path.dirname(BASE\u DIR),“myapp”,“static”,“templates”),
但我得到了同样的错误。你能帮助我吗?