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

编程入门 行业动态 更新时间:2024-10-08 22:51:21

AssertionError: Expected a `<a href=https://www.elefans.com/category/jswz/34/1768950.html style=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`

本文发布于:2024-03-15 08:51:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1738519.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Response   Expected   AssertionError   returned   HttpStreamingResponse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!