TemplateDoesNotExist

作者: tyc5116 (累人啊....)   2019-03-20 17:49:58
如題,照著Django官網的範例操作練習,測試template的效果
操作網頁上"Write views that actually do something"的大項中
結果遇到了這個問題,看起來它都會到非預期的地方撈取html
中英文的網頁都看了,找不到問題在哪
https://docs.djangoproject.com/en/2.1/intro/tutorial03/
簡稱說明如下
[VirtualEnv]: 建立虛擬環境的資料夾
[DjangoProj]: 放Django專案的資料夾
錯誤訊息如下
django.template.loaders.app_directories.Loader:
[VirtualEnv]\lib\site-packages\django\contrib\admin\templates\
polls\template\polls\index.html (Source does not exist)
django.template.loaders.app_directories.Loader:
[VirtualEnv]\lib\site-packages\django\contrib\auth\templates\
polls\template\polls\index.html (Source does not exist)
我的專案和虛擬環境習慣分開放(或是說這是不好的習慣?)
依我對官網上說明文件的理解,它應該要到[DjangoProj]\mysite\polls\template\polls
這個資料夾去找index.html
為什麼它會跑到上述的兩個錯的資料夾找呢?
手動把index.html放到上面兩個錯的資料夾的其中之一下,就能如預期顯示結果
或是在setting.py內的 TEMPLATES 補上
'DIRS': ['polls/template']
結果才會正常,請問是為什麼?
('APP_DIRS': 預設是True)
作者: zeus83157 (zeus83157)   2019-03-20 19:23:00
route 有設定嗎
作者: tyc5116 (累人啊....)   2019-03-20 21:02:00
關於哪個部份的route,我目前就都照網站一步步做而已
作者: froce (froce)   2019-03-22 18:34:00
你沒把你的app加到app列表,加了會自動吃app下templates資料夾的template。這一直是我覺得Django很迷的地方...
作者: tyc5116 (累人啊....)   2019-03-26 16:48:00
你是指加在INSTALLED_APPS內嗎??好像怪怪的

Links booklink

Contact Us: admin [ a t ] ucptt.com