前端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'的更多相关文章

  1. AttributeError: 'dict' object has no attribute 'has_key'

    运行下面的代码: if (locals().has_key('data')): del data gc.collect() 出错: if (locals().has_key('data')): Att ...

  2. AttributeError: 'dict' object has no attribute 'iteritems'

    在python3.6中运行 sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse= ...

  3. AttributeError: 'dict' object has no attribute 'encode'

    首先这是一个很简单的 运行时错误: 错误分析: AttributeError:属性错误,造成这种错误的原因可能有: 你尝试访问一个不存在的属性或方法.检查一下拼写!你可以使用内建函数 dir 来列出存 ...

  4. flask 表单填充数据报错!AttributeError: 'dict' object has no attribute 'getlist'

    报错信息: AttributeError: 'dict' object has no attribute 'getlist' 解决: 虽然是小毛病,不得不说还是自己太粗心大意了.

  5. facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'

    报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...

  6. 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”

    报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...

  7. 'dict' object has no attribute 'a'

    a = {} #a.a = 'a' #AttributeError: 'dict' object has no attribute 'a' #a['a'] #KeyError: 'a' a['a'] ...

  8. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  9. AttributeError: 'list' object has no attribute 'write_pdf'

    我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...

随机推荐

  1. POJ 3068 运送危险化学品 最小费用流 模板题

    "Shortest" pair of paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1215 ...

  2. luogu P1362 兔子数 x

    P1362 兔子数 题目描述 设 S(N ) 表示 N 的各位数字之和,如 S(484) = 4+8+4 = 16, S(22) = 2+2 = 4.如果一个正整数满足 S(x*x) = S(x) * ...

  3. 深度学习笔记(十)Augmentation for small object detection(翻译)

    一. abstract 这些年来,目标检测取得了令人瞩目的成就.尽管改进很大,但对于小目标和大目标的检测性能差异还是蛮大的.我们在 MS COCO 数据集上分析了如今一个比较先进的算法,Mask-RC ...

  4. Python3学习笔记(十):赋值语句和布尔值

    一.赋值语句 1.序列解包 多个赋值同时进行: >>> x,y,z = 1, 2, 3 >>> print(x, y, z) 1 2 3 变量交换: >> ...

  5. ZooKeePer总汇

    一.什么Zookeeper Zookeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization) ...

  6. 【学习】SpringBoot之简介、特点、缺点、应用场景

    Spring Boot 的介绍 SpringBoot的目的在于创建和启动新的基于Spring框架的项目.Spring Boot 会选择最合适的Spring子项目和第三方开源库进行整合.大部分Sprin ...

  7. MessageWebSocket

    using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; usi ...

  8. 浏览器端-W3School-JavaScript:JavaScript Math 对象

    ylbtech-浏览器端-W3School-JavaScript:JavaScript Math 对象 1.返回顶部 1. Math 对象 Math 对象用于执行数学任务. 使用 Math 的属性和方 ...

  9. MongoDB简单查询语句<平时使用语录,持续更新>

    MongoDB查询语句 --查询近三个月的客户使用量  aggregate:使用聚合  match:过滤  group分组   -- mysql中select org_code as 近三个月使用商户 ...

  10. ControlTemplate in WPF —— TreeView

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...