【已解决】Object of type 'QuerySet' is not JSON serializable
2017-09-01 20:49
295 查看
报错图片
报错的意思: QuerySet的数据格式不是JSON支持的序列化格式
我的代码:
def ajax_value(request):
ajax_testvalue = models.MonitorData02DB.objects.all().order_by("-id")[:1]
return JsonResponse(ajax_testvalue, safe=False)
这里要调用 from django.core import serializers 实现
参考原帖地址: Django model,QuerySet 序列化成json的方法
修改后
def ajax_value(request):
ajax_testvalue = serializers.serialize("json", models.MonitorData02DB.objects.all().order_by("-id")[:1])
return HttpResponse(ajax_testvalue)
即可生成Json数据
报错的意思: QuerySet的数据格式不是JSON支持的序列化格式
我的代码:
def ajax_value(request):
ajax_testvalue = models.MonitorData02DB.objects.all().order_by("-id")[:1]
return JsonResponse(ajax_testvalue, safe=False)
这里要调用 from django.core import serializers 实现
参考原帖地址: Django model,QuerySet 序列化成json的方法
修改后
def ajax_value(request):
ajax_testvalue = serializers.serialize("json", models.MonitorData02DB.objects.all().order_by("-id")[:1])
return HttpResponse(ajax_testvalue)
即可生成Json数据
相关文章推荐
- 【已解决】Object of type 'range' is not JSON serializable
- python2.7web代码用python3.6运行时,浏览器发送请求报错TypeError: Object of type 'bytes' is not JSON serializable的解决办法
- 在使用json.dumps时遇到报错TypeError: Object of type 'float32' is not JSON serializable
- TypeError: Object of type 'bytes' is not JSON serializable
- TypeError: Object of type 'float32' is not JSON serializable
- TypeError: datetime.datetime(2016, 9, 25, 21, 12, 19, 135649) is not JSON serializable解决办法(json无法序列化对象的解决办法)
- django object is not JSON serializable error问题解决
- Ubuntu下Firefox播放mp3显示HTTP "Content-Type" of "audio/mpeg" is not supported错误的解决办法
- Operation is not valid due to the current state of object 错误解决
- PHP JSON出错:Cannot use object of type stdClass as array解决方法
- object is not an instance of declaring class while invoking public abstract…的解决
- chrome浏览器Uncaught TypeError: object is not a function问题解决
- Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
- PHP JSON出错:Cannot use object of type stdClass as array解决方法
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- The application is not licensed to modify or create schema for this type of data 解决办法
- Operation is not valid due to the current state of the object解决方法
- mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func)
- Unable to add module to the current project as it is not of packaging type 'pom' 问题解决
- chrome浏览器Uncaught TypeError: object is not a function问题解决