django - TemplateDoesNotExist 位于 /home/entry/index.html、entry/entry_list.html
问题描述
我需要一双额外的眼睛,我只是看不到错误,下面你可以看到所有必要的文件,我认为错误来自那里
视图.py
from django.shortcuts import render
from django.views.generic import ListView
from .models import Entry
class HomeView(ListView):
model = Entry
template_name='entries/index.html'
网址.py
from .views import HomeView
from django.urls import path
urlpatterns = [
path('home/', HomeView.as_view(), name='blog-home')
]
基本网址.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('entries.urls'))
]
模板设置
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',
],
},
},
]
解决方案
你需要在 settings.py 添加模板目录,改变这个
'DIRS': [],
对此
'DIRS': ['templates'],
在 settings.py 文件中,模板设置
推荐阅读
- python - 如何在 Pandas 中将多个列表保存到多行中?
- docker - Kubernetes CrashLoopBackOff
- python - 多标签任务的平均编码
- amazon-web-services - AWS 检查配置为使用即将弃用或已弃用的运行时的 Lambda 函数
- c# - 变形器在统一时不适用于我的 mdoel
- sql - 如何使用 ID 从另一个表(sql server)获取名称值
- python - Python正则表达式在分组中返回不带双引号的单词
- c++ - 一个例子 condition_variable::notify_one
- sonarqube - “await”不应该冗余地用于 bot 框架
- laravel - 使用 cviebrock/eloquent-sluggable 时 Laravel 8 模型不更新