【发布时间】:2019-09-26 02:59:14
【问题描述】:
我的 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',
],
},
},
]
【问题讨论】:
-
您可以添加您的
TEMPLATES设置吗? -
你来了@JPG
-
模板未作为完整路径给出。请参阅有关模板查找系统的文档。
标签: python django django-templates django-views