AttributeError: 'dict' object has no attribute 'status_code'
前端AJAX请求数据,提示错误:“AttributeError: 'dict' object has no attribute 'status_code'”。
原因:是提示返回对象dict没有“status_code”属性,所以返回对象有问题。
views层的函数,有两个基本限制:
1.第一个数必须是request
2.必须返回HttpResponse类的一个实例(对象).
只返回了 字典类型的数据内容,没有用HttpResponse包裹一下字典。
return语句没有 render template或者 render json
改正后的代码如下,加了HttpResponse:
if request.is_ajax():
cpu_used = getCPUstate();
res_json = '{"cpu_used":cpu_used}'
# , 'mem_used':mem_used
return HttpResponse(res_json)
还需要注意一个问题:
传到前端的json必须要加单引号'',因为前端解析json是以字符串解析的,否则传输到前端的就是json对象会有问题。
前端json解析代码如下:
$.ajax({
url:"/linux_monitor/",
type:"GET",
dataType:"", //
processData:false,
contentType:false,
success:function (rdata) {
json_data = JSON.parse(rdata);
},
error:function(){
}
});
AttributeError: 'dict' object has no attribute 'status_code'的更多相关文章
- AttributeError: 'dict' object has no attribute 'has_key'
运行下面的代码: if (locals().has_key('data')): del data gc.collect() 出错: if (locals().has_key('data')): Att ...
- AttributeError: 'dict' object has no attribute 'iteritems'
在python3.6中运行 sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse= ...
- AttributeError: 'dict' object has no attribute 'encode'
首先这是一个很简单的 运行时错误: 错误分析: AttributeError:属性错误,造成这种错误的原因可能有: 你尝试访问一个不存在的属性或方法.检查一下拼写!你可以使用内建函数 dir 来列出存 ...
- flask 表单填充数据报错!AttributeError: 'dict' object has no attribute 'getlist'
报错信息: AttributeError: 'dict' object has no attribute 'getlist' 解决: 虽然是小毛病,不得不说还是自己太粗心大意了.
- facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'
报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...
- 'dict' object has no attribute 'a'
a = {} #a.a = 'a' #AttributeError: 'dict' object has no attribute 'a' #a['a'] #KeyError: 'a' a['a'] ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- AttributeError: 'list' object has no attribute 'write_pdf'
我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...
随机推荐
- buuctf@pwn1_sctf_2016
from pwn import * sh=remote('pwn.buuoj.cn',20086) get_flag=0x08048F0D payload='I'*0x14+'a'*4+p32(get ...
- jsp九大内置对象及四个作用域【转】
1.Request对象 该对象封装了用户提交的信息,通过调用该对象相应的方法可以获取封装的信息,即使用该对象可以 获取用户提交的信息. 当Request对象获取客户提交的汉字字符时,会出现乱码问题,必 ...
- 定时任务spring task
1)spring boot 几种定时任务的实现方式:https://www.jianshu.com/p/b6809b5a0c26 2)spring-boot 定时任务之Scheduled Task:h ...
- cordova打包遇到Connection timedout:
在cordova项目打包时,有时候处在公司内网环境,导致有些文件无法下载报下面的错误: A problem occurred configuring root project 'android'. & ...
- POJ 2456 编程技巧之------二分查找思想的巧妙应用
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18599 Accepted: 8841 ...
- vue router 报错:NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}
https://blog.csdn.net/weixin_43202608/article/details/98884620
- iview之avatar组件
avatar组件是一个获取网络路径图片的组件 它再vue中使用的话build时不会被打包,路径仍然为原来的路径 所以相对路径不会有效 如下: <Avatar style="margin ...
- Mongo Cursor
简介 在使用 Java 对数据库进行连接时,都会获取到一个 cursor ,cursor 实际指到的是我们查询数据库的query,而并不是 query 查询到的数据集. 此次在使用 mongo 的 c ...
- Filter、Listener、Interceptor、Controller in a Request
从以下程序运行Log 可以看出在一个Request 执行过程中 MyListener>>requestInitialized >>> MyFilter>> ...
- 树莓派安装parrot linux记录
手头这台树莓派3b安装parrot linux arm遇到了不少问题,写篇博客记录一下. 1.下载和刻录 网址:https://www.parrotsec.org/download-other.php ...