我盡我所能來源並解決了這個問題,但我似乎無法找到答案。TemplateDoesNotExist at/rango/
目前通過tangowithdjango教程,我目前在5.模板和靜態媒體。 http://www.tangowithdjango.com/book17/chapters/templates_static.html
試圖讓我的網站顯示其第一個模板,但我到了5.2我試圖加載我的網站,並得到這個錯誤信息之前:
TemplateDoesNotExist at /rango/
rango/index.html
Request Method: GET
Request URL: http://127.0.0.1:8000/rango/
Django Version: 1.8
Exception Type: TemplateDoesNotExist
Exception Value:rango/index.html
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib
/python2.7/site-packages/django/template/loader.py in get_template, line 46
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7
/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.9
這裏是我的settings.py文件:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
# Template from tangowithdjango 5.1: Templates and Static Media
#
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
TEMPLATE_PATH,
)
這裏是我的views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
# Construct a dictionary to pass to the template engine as its context.
# Note the key boldmessage is the same as {{ boldmessage }} in the template!
context_dict = {'boldmessage': "I am bold font from the context"}
# Return a rendered response to send to the client.
# We make use of the shortcut function to make our lives easier.
# Note that the first parameter is the template we wish to use.
return render(request, 'rango/index.html', context_dict)
對於評論的抱歉,經過幾次嘗試,我複製了網站的代碼,但仍然沒有成功。
我的文件結構如下:
工作區
-
- tango_with_django_project
-
-
- manage.py 個
-
-
-
- tango_with_django_project
-
-
-
-
- 設置。PY
-
-
-
-
- 模板
-
-
-
-
- 蘭戈
-
-
-
-
-
-
- 的index.html
-
-
-
要添加,這裏是顯示在127.0.0.1:8000/rango:
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/site-packages/django/contrib/admin/templates/rango/index.html (File does not exist)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/site-packages/django/contrib/auth/templates/rango/index.html (File does not exist)
感謝,這爲我工作! – TomG466