AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from

AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from,第1张

背景

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 ``
原因

views.py里return需要是Response或者他的父类,由于疏忽(菜鸡),直接返回了字典:

return {"code": 3466, "message": e}
解决

返回语句修改为:

return Response({"code": 3466, "message": e})
反思与规避

对django架构还是不了解,以后多花时间学习。
好记性不如赖笔头(多敲代码)。共勉。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/722782.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存