Object of type 'QuerySet' is not JSON serializable


在Django框架中,我们不能直接将QuerySet对象通过 HttpResponse(json.dumps(QeurySet))返回给前端Ajax....

否则会报错:Object of type 'QuerySet' is not JSON serializable

 

因此需要序列号后才能返回给前端Ajax....

from django.core import serializers

def ajax_value(request):
    ajax_testvalue = serializers.serialize("json", models.MonitorData02DB.objects.all().order_by("-id")[:1])
    return HttpResponse(ajax_testvalue)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM