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

前端 未结 3 685
余生分开走
余生分开走 2020-11-28 03:03

I am learning Django 1.6.
I want to post some JSON using HTTP POST request and I am using Django for this task for learning.
I tried to use request.POST[\'data

相关标签:
3条回答
  • 2020-11-28 03:32

    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)
    
    0 讨论(0)
  • 2020-11-28 03:36

    For python3 you have to decode body first:

    received_json_data = json.loads(request.body.decode("utf-8"))
    
    0 讨论(0)
  • 2020-11-28 03:41

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

    0 讨论(0)
提交回复
热议问题