this is the structure of projectDjango的錯誤,TemplateDoesNotExist在/你好
urls.py------
enter code here
from django.conf.urls import url
from django.contrib import admin
from . import search,view
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^search-form$', search.search_form),
url(r'^search$', search.search),
url(r'^test$',search.test),
url(r'^hello$',view.hello)
]
setting.py------
ROOT_URLCONF = 'HelloWorld.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR+"/templates",],
'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',
],
},
},
]
------the error------
TemplateDoesNotExist at /hello
hello.html
Request Method: GET
Request URL: http://127.0.0.1:8000/hello
Django Version: 1.7.11
Exception Type: TemplateDoesNotExist
Exception Value:
hello.html
Exception Location: /Library/Python/2.7/site-packages/Django-1.7.11-py2.7.egg/django/template/loader.py in find_template, line 136
Python Executable: /usr/bin/python
Python Version: 2.7.10
Python Path:
['/Users/xStraybird/HelloWorld',
'/Library/Python/2.7/site-packages/Django-1.7.11-py2.7.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Fri, 14 Apr 2017 13:23:10 +0000
i tried many ways in templates's dirs,such as
'DIRS':[BASE_DIR + 「/模板」,], 'DIRS': '/用戶/ xStraybird /的HelloWorld /模板', 但它不工作... Django的版本是1.7.11 我不能肯定是路徑錯誤...任何幫助嗎?非常感謝....
創建變量中列出的應用程序模板在settings.py中命名爲'TEMPLATE_PATH',即'TEMPLATE_PATH = os.path.join(BASE_DIR,'templates')'和寫入'DIR:[TEMPLATE_PATH,],' –
仍然錯誤....... TEMPLATE_PATH = os .path.join(BASE_DIR, '模板') TEMPLATES = [{ 'BACKEND':「DJA ngo.template.backends.django.DjangoTemplates', 'DIRS':[TEMPLATE_PATH,], 'APP_DIRS':真, '選項':{ 'context_processors':[ 'django.template.context_processors.debug' , 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] –
看到我的答案在下面.. –