Как получить доступ к телу запроса Django из Javascript?
Я делаю следующий запрос в JS к конечной точке API Django.
params = {"amount": String(amount), "currency": "usd", "description": "label"};
console.log(params)
var clientSecret = await fetch('https://url.com/api/payment/', {
method: 'POST',
body: params,
headers: {
'Content-Type': 'application/json'
},
}).then(r => r.json())
Вот вид
def payment(request, *args, **kwargs):
print("here")
body = request.POST.copy()
print("present")
print(body)
print(type(body))
print(list(body))
headers_in = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer key',
}
response = requests.post('https://api.stripe.com/v1/payment_intents',
headers=headers_in,
data=params_in)
return Response(response.json()['client_secret'])
body = request.POST.copy()
выдает мне Bad Request: /api/payment/
плохой запрос в моих журналах