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

199
Views
Csrftoken no está definido

Estoy usando el siguiente código según lo recomendado por la documentación:

 function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); }
 $("#formTabla").submit(function(event){ event.preventDefault(); var formData = new FormData(this); $.ajax({ beforeSend: function(xhr, settings) { if (!csrfSafeMethod(settings.type) && !this.crossDomain) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } } url : "{% url 'submit' %}", type: "POST", processData: false, contentType: false, data: { "checkboxes": formData, "datos": todosDatos }, success: function (respuesta){ } }); });

Estoy recibiendo el error:

 "Uncaught ReferenceError: csrftoken is not defined".

Entiendo por qué sucede esto, pero no tengo idea de cómo resolverlo. ¿Cómo y dónde se supone que debo definir crsftoken?

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

0

Puedes usar ajaxSend() para esto

 $(document).ajaxSend(function(event, xhr, settings){ if (!csrfSafeMethod(settings.type)) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } });
about 4 years ago · Juan Pablo Isaza Report

0

la variable no está definida en ninguna parte, primero debe obtener csrf_token:

 import Cookies from 'cookies-js' let csrftoken = Cookies.get('csrftoken')

luego configure la variable en el encabezado de la solicitud.

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!