Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

624
Vistas
How to include Django CSRF token in JavaScript API fetch?

I created simple API in Django and I need to fetch it with JavaScript, I get following error: Forbidden (CSRF token missing.): URL(placeholder instead of real url)

    fetch(`/Post/${content[i].id}`, {
        method: "POST",
       }).then((data) => {
            console.log(data);
        })

How can I include token in API call?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is an example and solution for your problem in Django official documentation.

const request = new Request(
    /* URL */,
    {
        method: 'POST',
        headers: {'X-CSRFToken': csrftoken},
        mode: 'same-origin' // Do not send CSRF token to another domain.
    }
);
fetch(request).then(function(response) {
    
});

I hope it could help you.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda