zoukankan      html  css  js  c++  java
  • django.db.models.query.QuerySet格式的数据输出

    1、

    def findmtm2(request):
    import serializer
    import json
    # 多对多跨表正向查询
    # res = softlist.objects.filter(hostlists__ip="10.116.6.177").values("softname")
    res2=softlist.objects.filter(hostlists__ip="10.116.9.233").values_list("softname")
    print("res2的数据输出是:",res2)

    print("res2的类型是:",type(res2))

    for nn in res2:
      print(nn,type(nn))


    for m in res2:
    # print(m,type(m))
      for mmm in m:
      print(mmm)

    return HttpResponse("ok,mtm2 search success!!!")

    ____________________________

    程序运行结果:

    res2的数据输出是: <QuerySet [('Acronis Backup',), ('Analytics Instance001',), ('CommCellConsole Instance001',), ('CommServe Instance001',), ('DiagnosticsAndUsageServer Instance001',), ('Java 8 Update 201 (64-bit)',), ('Java SE Development Kit 8 Update 201 (64-bit)',), ('MediaAgent Instance001',), ('MediaAgentCore Instance001',), ('MessageQueue Instance001',), ('Microsoft .NET Core Host - 2.1.16 (x64)',), ('Microsoft .NET Core Host - 2.1.5 (x64)',), ('Microsoft .NET Core Host FX Resolver - 2.1.16 (x64)',), ('Microsoft .NET Core Host FX Resolver - 2.1.5 (x64)',), ('Microsoft .NET Core Runtime - 2.1.16 (x64)',), ('Microsoft .NET Core Runtime - 2.1.5 (x64)',), ('Microsoft ASP.NET Core 2.1.16 Shared Framework (x64)',), ('Microsoft ASP.NET Core 2.1.5 Shared Framework (x64)',), ('Microsoft ASP.NET Core Module',), ('Microsoft Help Viewer 1.1',), '...(remaining elements truncated)...']>
    res2的类型是: <class 'django.db.models.query.QuerySet'>
    Acronis Backup
    Analytics Instance001
    CommCellConsole Instance001
    CommServe Instance001
    DiagnosticsAndUsageServer Instance001
    Java 8 Update 201 (64-bit)
    Java SE Development Kit 8 Update 201 (64-bit)

  • 相关阅读:
    微信授权登录
    mpvue 试水的一天
    小程序请求接口统一封装到一个js文件中
    工作中vue项目前后端分离,调用后端本地接口出现跨域问题的完美解决
    百度小程序授权更好体验
    关于智能小程序网络请求封装
    vue 开发webapp 手机返回键 退出问题
    MySQL解决存入数据库和取出数据库时间格式问题
    关于小程序授权更好体验
    关于vue项目中在js中引入图片问题
  • 原文地址:https://www.cnblogs.com/yaok430/p/14721925.html
Copyright © 2011-2022 走看看