问题是基于类的列表视图没有将数据传递给HTML。第一行1正在打印。它没有在for循环中打印第1行,这意味着它甚至没有进入for循环。
HTML文件如下所示
statusC.html
{% extends "base.html"%}
{% block body_block %}
<h3><span class="icon hk-icon-sm hk-icon-app"></span> Click line to make changes </h3>
<br><br>
<a href=""><h2>{{details}}Line 1</h2></a><br>
{% for details in line_list %}
<a href=""><h2>{{details.lineNo}}Line 1</h2></a><br>
{% endfor %}
{% endblock %}
urls.py
path('linelist',views_auth.linelistView.as_view(),name="linelist"),
基于类的列表视图如下
class linelistView(LoginRequiredMixin,ListView):
content_object_name ='line_list'
model = LineDetails
template_name = 'statusC.html'
模型
class LineDetails(models.Model):
postno =models.IntegerField(_('Post No'),unique=True)
lineNo = models.IntegerField(_('Line No'),default=1)
timeD = models.CharField(_('Estimated repair Time'),default="1 hour", max_length=10,null=True, blank=True)
status = models.BooleanField(_('Status'),default=True)
reasonM = models.CharField(_('Reason for maintence'),default="Checking", max_length=255,null=True, blank=True)
def __str__(self):
return "Posr No: "+str(self.postno)