django 自带序列化组件效果

 

from django.core import serializers
def tt(request):
    data = request.GET
    data = dict(data)
    print(data)
    real_dict = {}
    for k, v in data.items():
        real_dict[k] = v[0]
    name = data["name"][0]
    id = data["id"][0]
    obj = FF(id=id,name=name)
    obj.save()

    obj = FF.objects.all()
    ret = serializers.serialize("json", obj)
    return HttpResponse(ret)

  返回值

[
    {
        "model": "app01.ff",
        "pk": 1,
        "fields": {
            "pdf": "",
            "name": "李四"
        }
    },
    {
        "model": "app01.ff",
        "pk": 2,
        "fields": {
            "pdf": "/Users/。。。/static/张三/sql查询语句_mbpEz2K.pdf",
            "name": "张三"
        }
    },
    {
        "model": "app01.ff",
        "pk": 3,
        "fields": {
            "pdf": "/Users/。。。/static/张三/sql查询语句_VPbGcYQ.pdf",
            "name": "张三"
        }
    }
]

  

 

posted @ 2019-11-25 23:40  real-admin  阅读(172)  评论(0编辑  收藏  举报