У меня есть следующий вид в моем проекте Django:
import os
from django.shortcuts import render
from JumboDjango import settings
# Create your views here.
def index(request):
filename = os.path.join(settings.BASE_DIR, 'frontend/source/public/index.html')
return render(request, filename)
Но, когда он вызывается, он вызывает следующее исключение:
Internal Server Error: /
Traceback (most recent call last):
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/hugovillalobos/anaconda3/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjango/frontend/views.py", line 8, in index
return render(request, filename)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/template/loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "/Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjangoVenv/lib/python3.7/site-packages/django/template/loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: /Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjango/frontend/source/public/index.html
[26/Sep/2019 02:51:04] "GET / HTTP/1.1" 500 79956
Вы можете увидеть следующееизображение, которое /Users/hugovillalobos/Documents/Code/JumboDjangoProject/JumboDjango/frontend/source/public/index.html
действительно существует:
Я не знаю, пропускаю ли я какую-либо конфигурацию Django или что-то в этом роде.
РЕДАКТИРОВАТЬ
Это мои настройки шаблона:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]