Isomorphic sampling and Django view
I am sending a POST request to a Django view using isomorphic fetch.
body : "{"email":"admin@example.com","password":"11"}"
credentials : "same-origin"
headers :
Accept : "application/json"
Content-Type : "application/json"
X-CSRFToken : "mudIfipiyLUao2ZWwoEotFOUknYeVpZASNpQQ2IdadRVOe0a9n5tUqcKzwtrDuWX"
method : "POST"
When I submit this DRF view request, I can read the data with request.data
. However, when I post the same data to the Django view, request.POST is empty.
What could be the reason?
source to share
It looks like isomorphic sampling probably doesn't play a decisive role in why is request.POST
empty, but rather what request.POST
appears to be filled with form data rather than JSON data. This is confirmed by this quote from the Django REST Framework docs:
It (request.data) supports flexible parsing of REST Framework requests, not just support form data
Also take a look at the Malcom Tredinnick recommendations:
If you are using REST based web service stuff ... you should ignore request.POST
This refers to the fact that DRF handles a lot of things behind the scenes for you, such as serializing things and assigning to various variables, and interacting with pure Django equivalents. You may get strange results.
source to share