首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Django中的for循环不显示数据库结果?

Django中的for循环不显示数据库结果?

提问于 2022-06-15 15:58:52
回答 1关注 0查看 204
  • customer.html
代码语言:js
复制
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Customer of the Harbin Grocery Website </title>
</head>
<body>
    <h1>Customer List</h1>

    <table border='1' style='border-collapse:collapse'>
      {% for customer in customers_list %}
      <tr>
        <td>
           {{customer.firstname}}
        </td>
        <td>
           {{customer.lastname}}
        </td>
        <td>
           {{customer.address}}
        </td>
        </tr>
      {% endfor %}
    </table>

</body>
</html>
  • views.py
代码语言:js
复制
from django.views.generic import TemplateView, ListView
from .models import Customer

class HomePageView(TemplateView): 
    template_name = "home.html"

class AboutPageView(TemplateView):
    template_name = "about.html"

class ContactPageView(TemplateView):
    template_name = "contact.html"

class CustomerView(ListView):
    model=Customer
    template_name = "customer.html"
  • urls.py
代码语言:js
复制
from django.urls import path 
from .views import HomePageView, AboutPageView, ContactPageView, CustomerView

urlpatterns = [ 
    path("", HomePageView.as_view(), name="home"), 
    path("about/", AboutPageView.as_view(), name="about"), 
    path("contact/", ContactPageView.as_view(), name="contact"), 
    path("customer/", CustomerView.as_view(), name="customer"), 

    ]

实际页面显示效果(未显示添加顾客姓名)
实际页面显示效果(未显示添加顾客姓名)
已经添加的顾客姓名
已经添加的顾客姓名
想要达到的页面效果
想要达到的页面效果

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档