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

622
Views
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 answers
Answer question

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 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!