首页 > 技术文章 > Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.

poloyy 2021-08-21 23:31 原文

背景

有一个 Flask 项目,然后有一个路由返回的是 dict

 

通过浏览器访问,结果报错

 

关键报错信息

TypeError: 'dict' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.

意思是不能返回 dict

 

解决方案

结果是版本太老了,用的 Flask 1.0.2....我服了,之前跑别人的项目装了个老版 Flask,装个最新版本就好了...

推荐阅读