如何在my index.html上显示mysql的几名员工?

views.py中的索引代码

def index(request):
employees = Employee.objects.all()
schedules = []

for e in employees:

    s = Schedule.objects.filter(employee_id=e.employee_id,is_active=1)

    if (s.count() > 0):
        data = {}
        data['employee_id'] = e.employee_id
        data['schedule'] = s
        schedules.append(data)

context = {
    "employees": employees,"schedules": schedules
}

print(request.user.username)
return render(request,'index.html',context)

索引的高度

 <div class="col-md-3 parent">
<div class="card card-profile">
  <div class="card-avatar">
    <a href="#pablo">
      <img class="img" src="{% static 'img/faces/marc.jpg' %}">
    </a>
  </div>
  <div class="card-body">
    <h5 class="card-category text-gray">{{ employee.job_title.job_title }}</h5>
    <h4 class="card-title">{{ employee.first_name }}  {{ employee.last_name }}</h4>
      <h6 class="card-category text-gray">ILO - {{ employee.employee_id }}</h6>
      <h6 class="card-category text-gray">HOME HEALTH</h6>
    <p class="card-description" style="font-weight:bold">

我的问题是我在mysql数据库上有几个员工,我想向这些员工展示  在Index Page上,目前只有一名员工出现。谢谢您的帮助。

weidadeshuaigege 回答:如何在my index.html上显示mysql的几名员工?

在模板中的员工上使用循环

<div class="col-md-3 parent">
<div class="card card-profile">
  <div class="card-avatar">
    <a href="#pablo">
      <img class="img" src="{% static 'img/faces/marc.jpg' %}">
    </a>
  </div>
  <div class="card-body">
    {% for employee in employees %}
    <h5 class="card-category text-gray">{{ employee.job_title.job_title }}</h5>
    <h4 class="card-title">{{ employee.first_name }}  {{ employee.last_name }}</h4>
      <h6 class="card-category text-gray">ILO - {{ employee.employee_id }}</h6>
      <h6 class="card-category text-gray">HOME HEALTH</h6>
    {% endfor %}
    <p class="card-description" style="font-weight:bold">
本文链接:https://www.f2er.com/3162380.html

大家都在问