Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在my index.html上显示mysql中的几个员工?_Python_Django - Fatal编程技术网

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

Python 如何在my index.html上显示mysql中的几个员工?,python,django,Python,Django,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

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)
指数的Hmtl

 <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">

{{employee.job\u title.job\u title}
{{employee.first_name}{{employee.last_name}}
国际劳工组织-{employee.employee_id}
家庭健康

我的问题是我在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">

{employees%%中的员工为%s}
{{employee.job\u title.job\u title}
{{employee.first_name}{{employee.last_name}}
国际劳工组织-{employee.employee_id}
家庭健康
{%endfor%}


必须循环模板中的
employees
变量