2016-09-28 64 views
1

根據Django文檔Django的模板加載器不能達到應用模板

「你的項目的模板設置介紹Django會如何加載和渲染模板。默認設置文件配置一個DjangoTemplates後端,其APP_DIRS選項設置爲True。按照慣例DjangoTemplates在每個INSTALLED_APPS中查找「templates」子目錄。「

我的夾層settings.py有此配置

TEMPLATES = [ 
{ 
    'BACKEND': 'django.template.backends.django.DjangoTemplates', 
    'DIRS': [], 
    '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', 
     ], 
    }, 
}, 

]

我的目錄結構是

project 
    app_name 
     templates 
      app_name 
       index.html 

但模板加載器在

project 
    app_name 
     templates 

A停止這是我的app_name模板index.html沒有達到。可能是什麼問題?

回答

0

你嘗試改變你的模板迪爾斯上setting.py這樣

'DIRS': ["templates"], 

並沒有你views.py提供模板的具體位置達成您的模板例如

return render(request, 'foldername/templatename.html', {}) 
+0

任何使Django遞歸到'templates'目錄之外的目錄的方法嗎? – JTheboss

+0

閱讀這個[網站](http://stackoverflow.com/questions/1740436/what-is-the-best-location-to-put-templates-in-django-project)也許會有助於回答你的問題,但在您的應用程序目錄中創建一個'templates'目錄是存儲您的應用程序特定模板的理想選擇。 –