serialize datetime to json in Django

前端 未结 3 1165
渐次进展
渐次进展 2020-11-30 05:11

Hi how do I get DateTimeField from Mysql database in Django in json format? I got an error when I executed the code \'Date.time cannot be serialized in json\'(data holds a l

3条回答
  •  猫巷女王i
    2020-11-30 05:21

    DjangoJSONEncoder solved my problem.

    import json
    from django.core.serializers.json import DjangoJSONEncoder
    data = json.dumps(data, cls=DjangoJSONEncoder)
    

提交回复
热议问题