fastest way to create JSON to reflect a tree structure in Python / Django using mptt

后端 未结 4 1583
别跟我提以往
别跟我提以往 2021-01-30 14:54

What\'s the fastest way in Python (Django) to create a JSON based upon a Django queryset. Note that parsing it in the template as proposed here is not an option.

The ba

4条回答
  •  广开言路
    2021-01-30 15:13

    Organise you data into nested dictionaries or lists then call the json dump method:

    import json   
    data = ['foo', {'bar': ('baz', None, 1.0, 2)}]
    json.dump(data)
    

提交回复
热议问题