簡體   English   中英

Heroku找不到Django模板

[英]Heroku can't find Django templates

我在Heroku上查找我的html文件時遇到TemplateDoesNotExist錯誤。 這些文件都在開發服務器上同步。 TEMPLATE_DIRS設置設置為:

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

但是當我嘗試加載頁面時,我發現了以下錯誤:我認為這里有一些非常基本的東西。

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+中,更改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