首页 > 解决方案 > Django 应用程序找不到位于项目模板内的 base.html - Django 3.2

问题描述

尽管我以前使用 ASP.NET 进行过 Web 开发,但我还是 Django 新手。我按照本教程创建了一个 Django 项目来执行用户管理 - https://realpython.com/django-user-management/

我使用命令 - 在项目 lipreading_website 中创建了一个名为 users 的应用程序 - python manage.py startapp users

然后我在这个应用程序中创建了模板文件夹 - users/templates 并将 base.html 文件放在 users/templates 中,并将其余的 HTML 文件创建在users/templates/users/. 然后,我从users/templates/users使用{% extends "base.html" %}.

然后我按照本教程 - https://www.youtube.com/watch?v=vXXfXRf2S4M&t=2s&ab_channel=Pyplane添加了一些应用程序 - 测验、结果、问题并base.html在项目模板中添加新文件 -> lipreading_website/templates/base.html

我对 settings.py 文件进行了以下更改-

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
                os.path.join(BASE_DIR, 'templates')
            ],
        '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',
            ],
        },
    },
]

并继续扩展此文件,而不是从quizzes/templates/quizzes/main.html.

我想在项目根模板文件夹中扩展 base.html,但它仍然引用在 users/templates/ 文件夹中创建的 base.html。

标签: pythonhtmldjango

解决方案


推荐阅读