Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from"/>
AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from
背景
python 3.7.6
django 2.2
现象
执行run后通过postman调用接口报错:
AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'dict'>`
原因
views.py里return需要是Response或者他的父类,由于疏忽(菜鸡),直接返回了字典:
return {"code": 3466, "message": e}
解决
返回语句修改为:
return Response({"code": 3466, "message": e})
反思与规避
对django架构还是不了解,以后多花时间学习。
好记性不如赖笔头(多敲代码)。共勉。
更多推荐
AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse`
发布评论