python – Heroku找不到Django模板
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – Heroku找不到Django模板,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1883字,纯文字阅读大概需要3分钟。
内容图文
我在Heroku上查找我的html文件时遇到TemplateDoesNotExist错误.这些文件都在开发服务器上同步. 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)
解决方法:
您需要更新您的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")],
...
}
]
内容总结
以上是互联网集市为您收集整理的python – Heroku找不到Django模板全部内容,希望文章能够帮你解决python – Heroku找不到Django模板所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。