Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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
Jsonify from def在python中返回空_Python - Fatal编程技术网

Jsonify from def在python中返回空

Jsonify from def在python中返回空,python,Python,我有一个def函数,它以数组的形式返回查询结果并返回jsonify,但它返回的是空的 def是 @app.route('/newsearchresults') def newsearchresults(): name = request.args.get('query') customers = {} customers = Customer.query.filter(Customer.name.like('%'+str(name)+'%')).a

我有一个def函数,它以数组的形式返回查询结果并返回jsonify,但它返回的是空的

def是

@app.route('/newsearchresults')
def newsearchresults():
        name = request.args.get('query')
        customers = {}
        customers = Customer.query.filter(Customer.name.like('%'+str(name)+'%')).all()
        return jsonify(customers)
HTML表单如下所示,它调用jquery函数

<form action="/newsearchresults" >
  <Text  text="Customer Name" id="text0"/>
  <Input width="200px"  name="custName"  required  placeholder="Please enter the customer name"/>
  <button  type="submit">Search Customer</button>
 </form>
我想将jsonify响应结果填充到下表的同一html文件中

<table border="1" >
            <tr><td><strong>Customer Id</strong></td><td><strong>Name</strong></td><td><strong>E Mail</strong></td> <td><strong>Mobile No</strong></td></tr>
             {% for name1 in customers %}
             <td><a class="customername" href="#" data-name="{{ name1.name }}">{{name1.id}}</a></td><td>{{name1.name}}</td><td>{{name1.email}}</td><td>{{name1.mobileno}}</td></tr>

             {% endfor %}
        </table>

客户Id姓名电子邮件手机号码
{customers%%中name1的%1}
{{name1.name}{{name1.email}{{name1.mobileno}}
{%endfor%}

您是否检查了从查询中获得的非空响应,def函数在jsonify之前工作正常,但随后返回jsonify不工作,返回空。
<table border="1" >
            <tr><td><strong>Customer Id</strong></td><td><strong>Name</strong></td><td><strong>E Mail</strong></td> <td><strong>Mobile No</strong></td></tr>
             {% for name1 in customers %}
             <td><a class="customername" href="#" data-name="{{ name1.name }}">{{name1.id}}</a></td><td>{{name1.name}}</td><td>{{name1.email}}</td><td>{{name1.mobileno}}</td></tr>

             {% endfor %}
        </table>