django: control json serialization

前端 未结 4 1261
执笔经年
执笔经年 2021-01-16 09:41

Is there a way to control json serialization in django? Simple code below will return serialized object in json:

co = Collection.objects.all()
c = serializer         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 10:08

    I would suggest you use the json library to encode your data, instead of just constructing the json-like string yourself. The code above doesn't seem to handle escaping properly, for one thing. And there's not much to gain by writing your own serializer (except for bugs).

提交回复
热议问题