【发布时间】:2017-06-09 09:14:27
【问题描述】:
我之前看到过这个问题,但我已经在使用较新的 TEMPLATES 数据结构,这是常见的解决方案。
来自 tango with django book,我目前在第 4 单元。当我使用 python manage.py runserver 运行我的程序时
我收到以下错误:
TemplateDoesNotExist at /rango/
rango/index.html
Request Method: GET
Request URL: http://127.0.0.1:8000/rango/
Django Version: 1.5.1
Exception Type: TemplateDoesNotExist
Exception Value:
rango/index.html
这是我~/Workspace/wad2/tango_with_django_project/setings.py文件中的相关代码:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'tango_with_django_project', 'templates')
.
.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'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',
],
},
},
]
.
.
另外,这是我的~/Workspace/wad2/rango/views.py 文件中的相关代码:
def index(request):
context_dict = {'boldmessage': "Crunchy, creamy, cookie, candy, cupcake!"}
return render(request, 'rango/index.html', context_dict)
此外,我无法通过直接路径解决此问题,因为我试图坚持使用动态 pahs 的教程。最后,我的模板位于~/Workspace/wad2/tango_with_django_project/templates/rango/index.html
【问题讨论】:
-
尝试将
APP_DIRS: True添加到您的模板字典 (docs) -
@Sayse,我已经有了。我将编辑我的问题以包含它。
-
等等,你的错误提示你使用的是 Django 1.5.1?...
-
@AlexanderTyapkov:我在问题的末尾包含了结构。
-
然后不要使用新的模板设置,使用
TEMPLATE_DIRS或任何1.5.1 使用或升级到支持的django 版本。