Django TemplateDoesNotExist:home.html、femat/law_list.html
为什么我在没有定义或请求“law_list.html”时会出现上述错误?law_list.html从何而来?模型和基于类的视图应该有问题。我正在使用Django3.1.3Django TemplateDoesNotExist:home.html、femat/law_list.html,django,django-models,django-views,Django,Django Models,Django Views,为什么我在没有定义或请求“law_list.html”时会出现上述错误?law_list.html从何而来?模型和基于类的视图应该有问题。我正在使用Django3.1.3 #models.py from django.db import models class Law(models.Model): name = models.CharField(max_length=100) E = models.FloatField(null=False, blank=False, de
#models.py
from django.db import models
class Law(models.Model):
name = models.CharField(max_length=100)
E = models.FloatField(null=False, blank=False, default=0)
def __str__(self):
return '{} {}'.format(self.name, self.E)
#views.py
from django.views.generic import ListView
from .models import Law
class HomeView(ListView):
model = Law
template_name = 'home.html'
#urls.py
from django.urls import path
from .views import HomeView
urlpatterns = [
path('', HomeView.as_view(), name='home'),
]
这应该做到:
template_name= "femat/home.html"
向我们展示整个错误回溯信息,而不仅仅是最后一行。是的,它现在呈现正确。非常感谢。我仍然无法理解错误消息的第二部分。Law_list.html是ListView将查找的默认html,它是从您的模型名派生的。见