Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to post list of dictionary in django test client?

As Django Test Client accepts only data={} as an input I am not able to pass a list of dict i.e data=[{},{},{}] to it. Any solution for this?

like image 996
Jd16 Avatar asked Oct 18 '16 07:10

Jd16


Video Answer


2 Answers

This worked:

response = client.post(url, json.dumps(data), content_type='application/json')
like image 148
Jd16 Avatar answered Oct 10 '22 12:10

Jd16


You can pass the values as a list in the dict:

data={"key": [{"key":"value"}, {"key":"value"}]}

Alternatively you can use a MultiValueDict as the value.

You can pass as a list also

import requests
data = [{"key":"value"}, {"key":"value"}]
a = requests.post('http://url', data)
like image 28
NIKHIL RANE Avatar answered Oct 10 '22 13:10

NIKHIL RANE