How to receive json data using HTTP POST request in Django 1.6?

£可爱£侵袭症+ 提交于 2019-11-27 02:58:09

You're confusing form-encoded and JSON data here. request.POST['foo'] is for form-encoded data. You are posting raw JSON, so you should use request.body.

received_json_data=json.loads(request.body)

For python3 you have to decode body first:

received_json_data = json.loads(request.body.decode("utf-8"))

Create a form with data as field of type CharField or TextField and validate the passed data. Similar SO Question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!