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
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'))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With