2👍
✅
Since you followed the example provided in the api-guide and it works in shell I think that the data is not being sent properly.
Django Rest Framework uses APIClient
for testing which is based on Django’s Test Client
If you don’t provide a content type
the default value is multipart/form-data
If you don’t provide a value for
content_type
, the values indata
will be transmitted with a content type ofmultipart/form-data
. In this case, the key-value pairs in data will be encoded as amultipart
message and used to create thePOST
data payload.
You will need to explicitly specify the format
of the data as json
:
response = self.client.post('/api/qnr/', data=qnr2, format='json')
👤AKS
Source:stackexchange.com