我的應用程式在本地與生產設定和資料庫一起正常作業,我成功地將應用程式部署到 Heroku。這是我的專案結構:
root folder
env
src
app
fund
static
staticfiles
templates
includes
funds_table.html
pagination.html
about_me.html
base.html
index.html
user_account
manage.py
requirements.txt
Procfile
.gitignore
這是我的模板設定:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR), 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我檢查了os.path.join(BASE_DIR)回傳正確的路徑 - project_root/src。當我在 Heroku 上打開應用程式時,我收到錯誤訊息:
raise TemplateDoesNotExist(", ".join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: index.html, fund/fund_list.html
"GET / HTTP/1.1" 500 145 "https://dashboard.heroku.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
有趣的是,fund/fund_list.html我的應用程式中什至沒有。我嘗試Search Everywhere在 Pycharm 中使用,但該檔案不存在,甚至在任何地方都沒有提及。我不確定 Heroku 為何試圖找到它。
我做錯了什么?
uj5u.com熱心網友回復:
而不是這個:
[os.path.join(BASE_DIR), 'templates'] #You did wrong here. it should not like this
添加這個:
[os.path.join(BASE_DIR, 'templates')]
嘗試上面并再次上傳,看看它是否解決了問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529677.html
標籤:djangoheroku
