django+SQLite搭建轻量级个人博客(十)json.dumps转换queryset的datatime报错

一、问题

数据库查询,时间结果转换成json时,显示datatime.datatime

 

二、解决途径:

from django.core.serializers.json import DjangoJSONEncoder

aa = list(Student.objects.all().values())  #从数据库查询所有数据,转成list

ab = json.dumps(aa, ensure_ascii=False, cls=DjangoJSONEncoder)

 

return HttpResponse(ab)

 

 

三、参考

https://www.cnblogs.com/ianduin/p/7761400.html

posted @ 2019-10-31 00:39  hello_libra  阅读(240)  评论(0编辑  收藏  举报