【发布时间】:2015-11-28 14:33:56
【问题描述】:
我正在使用烧瓶和 gevent。我的功能如下:
@app.route('/index',methods=['POST'])
def index():
....
....
gevent.joinall(threads)
res = [t.value for t in threads]
return jsonify(**res)
生成的响应 (res) 是一个字典列表,如下所示:
[{u'token': u'146bf00b2cb96e6c425c2ab997637', u'a': u'aaa'},{u'token': u'146bf00b2cb96e6c425c2ab3f7417', u'a': u'bbb'}, {u'token': u'146bf00b2cb96e6c425c2ab3f5692', u'a': u'ccc'} ]
当我尝试 jsonify 时,我得到:
TypeError: jsonify() argument after ** must be a mapping, not list
我做错了什么?
【问题讨论】:
-
**适用于字典而不是列表,不知道 jsonify 函数的作用,但您可以使用jsonify(*res)或`jsonify(*res)` -
感谢 Padraic,* 运算符的名称是什么,我可以查一下吗?我知道**,但不知道*
-
再次感谢,这很有帮助!