Я пытаюсь отобразить простую страницу, но у меня возникла проблема.Django: TemplateDoesNotExist at /.../
TemplateDoesNotExist at /pages/
{}
Папка с шаблоном не найдена. вот мои конфигурации settings.py
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, 'pages/template')],
'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',
],
},
},
]
ли я сделал что-то не так?
--------------- CMD ----------------
Internal Server Error: /pages/
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\Scripts\src\pages\views.py", line 6, in index
return render('index.html', context)
File "C:\Python34\lib\site-packages\django\shortcuts.py", line 67, in render
template_name, context, request=request, using=using)
File "C:\Python34\lib\site-packages\django\template\loader.py", line 96, in render_to_string
template = get_template(template_name, using=using)
File "C:\Python34\lib\site-packages\django\template\loader.py", line 43, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: {}
[12/Jan/2016 20:51:57] "GET /pages/ HTTP/1.1" 500 74646
----- ------ UPDATE -------------
File Tree
views.py
from django.shortcuts import render
# Create your views here.
def index(request):
context = {}
return render(request, 'index.html', context)
пожалуйста, напишите вашу структуру каталогов проекта. – Saturnix
@Saturnix Обновлено – Lindow
переместите папку шаблона за пределы «страницы» и назовите это «шаблоны». Поместите в свои настройки: 'TEMPLATE_DIRS = (os.path.join (BASE_DIR, 'templates'),)'. Теперь в вашем view.py вызовите шаблон с помощью 'render ('index.html', context)' – Saturnix