django-rest-framework accept JSON data?

You need to do two step to done this issue:

  1. Add Content-Type header with application/json value
  2. Add Authorization header with Token {YOUR_CUSTOM_TOKEN} value to pass CSRFToken

Note: if you want to authenticate with session, you don't need to do second step, but if you want use this API for mobile, you have to pass Authorization header to server

I hope it helps


You have missed adding the Content-Type header in the headers section. Just set the Content-Type header to application/json and it should work.

See the below image:

postman

Also, you might also need to include a CSRF token in the header in case you get an error {"detail": "CSRF Failed: CSRF token missing or incorrect."} while making a POST request using Postman. In that case, add an X-CSRFToken header also with value as the CSRF token value.


I'm posting this answer in case someone is facing a problem like mine.

I'm working on a Front-End app using Angular 2 with an API made with Django Rest Framework and I used to send requests with the following headers:

'Content-Type': 'application/json'

And it was working fine until I tried it on Fire Fox and I couldn't load the needed data and I solved it with adding the following headers

'Content-Type': 'application/json',
'Accept': 'application/json'

Here's an explanation, Content-Type tells the server what is the content type of data is while Accept tells it what content type the client side will accpet.

Here's a nice clear answer about this issue:

https://webmasters.stackexchange.com/questions/31212/difference-between-the-accept-and-content-type-http-headers