【问题标题】:TypeError: The view function did not return a valid response tuple. The tuple must have the form (body, status, headers), (body, status),TypeError:视图函数没有返回有效的响应元组。元组的形式必须为 (body, status, headers), (body, status),
【发布时间】:2021-04-18 12:03:19
【问题描述】:

This is the pic of Mysql DB[这里是代码]https://i.stack.imgur.com/muX0s.png

在此之后,我希望 Mathew 成为输出,但错误即将到来 2https://i.stack.imgur.com/taUgq.png

【问题讨论】:

  • 请不要将代码放在图片中,请将其作为文本包含在问题中

标签: python mysql flask fetchall


【解决方案1】:

users 是一个元组列表。在您的图像中,您显示数据库仅包含一个字段,用于用户名。

因此,当您执行 users[0] 时,将返回大小为 1 的元组:('Matthew'),这不是有效的响应。

要返回 Matthew,您应该 return users[0][0]:[0] 从查询中获取第一行,[0] 从该行获取第一个字段(用户名)。

编辑:更新我的答案以匹配 OP 的 SQL 架构

【讨论】:

猜你喜欢
  • 2019-12-15
  • 1970-01-01
  • 2020-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-15
  • 2020-01-10
相关资源
最近更新 更多