【问题标题】:Django TemplateDoesNotExist at /rango/Django TemplateDoesNotExist 在 /rango/
【发布时间】: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 版本。

标签: django django-templates


【解决方案1】:

通过更新我的 django 版本解决了这个问题:

pip install django==1.10.5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2017-03-14
    • 1970-01-01
    • 2011-06-13
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    相关资源
    最近更新 更多