python - 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。
解决方案
推荐阅读
- matplotlib - plt.savefig 正在保存旧版本的情节
- javascript - 制作不同的随机数
- r - 在 QQplot 中为模型画线
- java - 如何通过 Log4j2 将日志发送到 Graylog?
- datetime - .Net Core 3.1 Web Api 的自定义 OData 日期时间序列化器
- python - 读取模板 JSON 文件并在 bash 或 Python 中使用替换创建新文件
- c# - WPF C# Mouse Down 事件以编程方式在 void
- r - 在 R 中有效地采样彩票号码
- python - 比较不需要模式匹配的 2 个列表
- html - 我的网站在本地托管时使用 flex 和 bootstrap 进行响应。它现在是在线托管的,flex 不能在移动网站上运行