django + SQLite to build lightweight personal blog (X) json.dumps conversion of datatime error queryset

First, the problem

When the database query time result into json, display datatime.datatime

 

Second, to address ways:

from django.core.serializers.json import DjangoJSONEncoder

aa = list (Student.objects.all (). values ​​()) # queries all data from the database into a list turn

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

 

return HttpResponse(ab)

 

 

Third, the reference

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

Guess you like

Origin www.cnblogs.com/xuexizongjie/p/11768979.html