如何使用python django通过单击下拉菜单从数据库中获取数据,使用Mysql db?

时间:2019-05-06 05:23:12

标签: python django-models

views.py文件

def show3(request):
    employees = Employee.objects.all().order_by().values('city').distinct()
    search4=''
    if 'search4' in request.GET:
       search4 = request.GET.getlist('search4')
       print(search4)
        employees=Employee.objects.filter(id__in=search4).distinct().order_by()
    return render(request,"testapp/show3.html",{'employees':employees})

show3.html文件

{% for employee in employees %}
  <li>
      <a href="/show3"><span name="search4" class="glyphicon glyphicon-pencil">{{ employee.city }}</span></a>
  </li>
{% endfor %}


<table class="table table-striped table-boedered table-sm">

  <thead class="thead-dark">
    <tr>
      <th>HostName</th>
    </tr>

  </thead>
  <tbody>
    {% for employee in employees %}
    <tr>
      <td><a href="/edit/{{ employee.id}}"><span class="glyphicon glyphicon-pencil"></span>{{ employee.host_name }}</span></a></td>
</tr>
{% endfor %}

</table> 

我想显示城市下拉列表,当我单击特定城市时,所有主机名都应属于该城市,所有进程都必须是动态的。...预先感谢

0 个答案:

没有答案