作者:
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)