博主在win7系統下使用django中遇到了該問題,查了下stackoverflow,發現一般的解決辦法如下:
在setting.py中的添加
TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates/'), os.path.join(BASE_DIR, 'templates/').replace('\\', '/'), )
博主添加后依然出現此問題,最后在錯誤頁面的Traceback 中找到了問題
Template Loader Error: Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: F:\python2.7\lib\site-packages\django-1.8.2-py2.7.egg\django\contrib\admin\templates\maby.html (File does not exist) F:\python2.7\lib\site-packages\django-1.8.2-py2.7.egg\django\contrib\auth\templates\maby.html (File does not exist)
Django並沒有去博主指定的文件夾中尋找模板文件,而是去到了兩個默認的文件夾中尋找,隨再次尋找答案,最終找到如下辦法:
修改setting.py,添加以下內容:
import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates/').replace('\\', '/')], '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', ], }, }, ]
再次啟動后,頁面成功加載。
希望能幫助到你,國內幾乎沒有什么資料=。=