Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Enviar POST de JS a Django

Estoy tratando de enviar POST con algunas variables a Django.

Enviar desde JS:

 function sendStatistic(csrftoken, song_id, answer) { fetch('request/', { method: 'POST', headers: { 'X-CSRFToken': csrftoken, 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: { 'Song-Id': song_id, 'Answer': answer ,}, }); }

E intente capturar 'Song-Id' y 'Answer' en Django pero:

 request.POST.get('Answer')

devuelve Ninguno

¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

ahora todo está bien. Cambié 'Tipo de contenido' y agregué 'nueva URLSearchParams' en el cuerpo

 function sendStatistic(csrftoken, song_id, answer) { fetch('request/', { method: 'POST', headers: { 'X-CSRFToken': csrftoken, 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ 'Song-Id': song_id, 'Answer': answer, }), }); }

Ahora puedo obtener mis variables en django

about 4 years ago · Juan Pablo Isaza Report

0

Pruebe request.body en lugar de request.POST

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!