用于API请求的python中的jsonify选项卡 - python

我在那儿,我从mysql这样得到一个标签:
{'jean': 22, 'pierre': 26, 'john': 21, 'charles': 23, 'test': 25, 'test2': 45}称为用户

我想像这样对它进行Jsonify:

[{
  "name": "jean"
  "age": 22
}
{
  "name": "pierre"
  "age" : 26
}
...

而且我做不到。请问你能帮帮我吗 ?

@app.route("/users", methods = ['GET'])
def getUsers():
    return jsonify({'users' : users}] 

参考方案

它看起来像这样:

d = {'jean': 22, 'pierre': 26, 'john': 21, 'charles': 23, 'test': 25, 'test2': 45}
res = []
for k, v in d.items():
  res.append({"name": k, "age": v})

print(res)

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

Python-使用请求时发布请求失败 - python

使用外壳程序时,我可以通过运行以下命令成功创建新用户curl --user administrator:pasword "Content-Type: application/json" https://localhost:8080/midpoint/ws/rest/users -d @user.json但是,当我尝试使用请求在python…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。