[Solved]-DRF test client unable to post list of JSON

26👍

You should specify json as format:

response = self.client.post(cart_item_url, data=data, format='json')

2👍

You can try this

response = self.client.post(cart_item_url, json.dumps(data), content_type='application/json')

this is working for me

1👍

Try specifying content_type as application/json.

response = self.client.post(cart_item_url, data=json.dumps(data), content_type='application/json')

0👍

Try:

response = self.client.post(cart_item_url, data=json.dumps(data)), headers={'Content-Type': 'application/json'})

Leave a comment