TemplateDoesNotExist

看板Python作者 (累人啊....)時間5年前 (2019/03/20 17:50), 編輯推噓1(105)
留言6則, 3人參與, 5年前最新討論串1/1
如題,照著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) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.89.192 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553075402.A.102.html

03/20 19:23, 5年前 , 1F
route 有設定嗎
03/20 19:23, 1F

03/20 21:02, 5年前 , 2F
關於哪個部份的route,我目前就都照網站一步步做而已
03/20 21:02, 2F

03/22 18:34, 5年前 , 3F
你沒把你的app加到app列表,加了會自動吃app下templates資
03/22 18:34, 3F

03/22 18:34, 5年前 , 4F
料夾的template。
03/22 18:34, 4F

03/22 18:35, 5年前 , 5F
這一直是我覺得Django很迷的地方...
03/22 18:35, 5F

03/26 16:48, 5年前 , 6F
你是指加在INSTALLED_APPS內嗎??好像怪怪的
03/26 16:48, 6F
文章代碼(AID): #1SaWpA42 (Python)