Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django - post data query dict is empty

i use postman app and set content-type : application/json and using post method in the body i select "raw" and "JSON(application/json)" and after all of this i enter a simple json :

{"token":"ghdfhldfigpd","text":"test Expense" ,"amount":10000}

but when i debug my django app : query dict is empty see this picture

but when i enter my data in form-data section my app works and post query dict is not empty what the problem should be ?

EDIT : i see that the data goes to body but not to post query dict: this picture

like image 901
Seyyed Mahdiyar Zerehpoush Avatar asked Jun 26 '18 15:06

Seyyed Mahdiyar Zerehpoush


1 Answers

request.POST is only for application/x-www-form-urlencoded data. Since you are using json, you should use request.body with json.loads.

import json

def my_view(request):
    data = json.loads(request.body.decode('utf-8'))
    ...
like image 62
Alasdair Avatar answered Nov 03 '22 16:11

Alasdair