0
Django에서 TemplateDoesNotExist를 푸는 방법?
설정 :
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), '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',
],
},
},
]
URL을 :
urlpatterns = [
url(r'^hello/$', hello),
url(r'^time/$', current_datetime),
url(r'^time/plus/(\d{1,2})/$', hours_ahead),
]
전망 :
def current_datetime(request):
now = datetime.datetime.now()
t = get_template('current_datetime.html')
html = t.render(Context({'current_date': now}))
return HttpResponse(html)
current_datetime.html :
,345,728,913,378,603,210그리고이있어 :
TemplateDoesNotExist at /time/
current_datetime.html
Request Method: GET
Request URL: http://127.0.0.1:8000/time/
Django Version: 1.10.5
Exception Type: TemplateDoesNotExist
Exception Value:
current_datetime.html
Exception Location: /Users/wonderful/anaconda/lib/python2.7/site-packages/django/template/loader.py in get_template, line 25
Python Executable: /Users/wonderful/anaconda/bin/python
Python Version: 2.7.12
Python Path:
['/Users/wonderful/mysite',
'/Users/wonderful/anaconda/lib/python27.zip',
'/Users/wonderful/anaconda/lib/python2.7',
'/Users/wonderful/anaconda/lib/python2.7/plat-darwin',
'/Users/wonderful/anaconda/lib/python2.7/plat-mac',
'/Users/wonderful/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/wonderful/anaconda/lib/python2.7/lib-tk',
'/Users/wonderful/anaconda/lib/python2.7/lib-old',
'/Users/wonderful/anaconda/lib/python2.7/lib-dynload',
'/Users/wonderful/anaconda/lib/python2.7/site-packages',
'/Users/wonderful/anaconda/lib/python2.7/site-packages/Sphinx-1.4.6-py2.7.egg',
'/Users/wonderful/anaconda/lib/python2.7/site-packages/aeosa',
'/Users/wonderful/anaconda/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg']
Server time: Tue, 7 Feb 2017 10:42:42 +0800
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/wonderful/mysite/mysite/templates/current_datetime.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/wonderful/anaconda/lib/python2.7/site-packages/django/contrib/admin/templates/current_datetime.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/wonderful/anaconda/lib/python2.7/site-packages/django/contrib/auth/templates/current_datetime.html (Source does not exist)
그 해결 방법을?
보이는 – karthikr
@karthikr 네, 그것은 귀하의 폴더가 "템플릿"라는 – ipreacher
및 설정에서 당신이 그것을 설명했다 "템플릿을 작동 " – Bijoy