Hello, first time here and I’ve seen like 300 StackOverflow issues and couldn’t solve it.
I want something simple, send this POST request:
axios({
headers: { 'content-type': 'application/json;charset=UTF-8'},
method: 'post',
url: 'http://localhost:8000/ledger/store',
data: {
ledger_id: "dxglowjdnomy",
transactions: [{
id: ".z9ditcvddqf",
section: 3,
description: "fasfd",
subsection: 8,
value: 4234,
date: "18/04/2020"}]
}
})
JSON is well formatted, if there is any issue is because it just an example of the data I’m sending.
And here is my Django view, nothing fancy:
@csrf_exempt
def store(request):
req_data = request.POST.get('ledger_id')
return JsonResponse({ 'data' : req_data })
But all i get in return is {data:null}
.
I tried serializers.serialize('json', request.POST.get('ledger_id'))
, but I got MultiValueDictKeyError at /ledger/store 'ledger_id'
In the frontend I’ve also tried stringifying the json object, but no luck either…
May it be a problem with CORS? I’m using different servers for this app…
I really don’t know what I’m doing wrong. If someone can please help me at least to point in the right direction, it will be really appreciated.
Thanks in advance.