Django saving json value to database/model

前端 未结 5 747
清歌不尽
清歌不尽 2020-12-28 19:30

Im new to django and im trying to save json to database. The problem is that im able to get data the data in my views but not sure how to save it in

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 20:11

    If you're using Postgres, you can store json with JSONField (read more), but if not, you need parse json to string and save with CharField/TextField using json.dumps(data). To recovery data, use json string to dict with json.loads(json_string)

    Remember to import json lib: import json

提交回复
热议问题