python - POST list to django restapi -


i trying post list of strings data unable receive list on server gave me last element of list

con = ["71qweq74520", "8324wqe57", "81ewqewq166"]  

received

con = 81ewqewq166 

code receive @ server api:-

@csrf_exempt @api_view(['post']) def getuser(request):     if request.method == 'post':         if isapivalid(request):             params in request.post:                 print params,request.post[params]                 #this prints last element of array/lis 

python scirpt post:-

con = ["71qweq74520", "8324wqe57", "81ewqewq166"]  data = { 'apikey':apikey, 'sig':sig ,'con': con} data2 = json.dumps(data) #hostname = '127.0.0.1:8000' hostname = 'xx.xx.xx.xx' method = 'method' task = 'getuser' url = 'http://'+ hostname + '/' + method + task r = requests.post(url, data=data) #r = requests.post(url, data=data2) fails 

how can posted list ??

output httpd log:-

 [wed jan 27 13:35:05.868468 2016] [:error] [pid 18858] api validation passed     [wed jan 27 13:35:05.868512 2016] [:error] [pid 18858] 81ewqewq166     [wed jan 27 13:35:05.868547 2016] [:error] [pid 18858] 1 99qwerty99     [wed jan 27 13:35:05.868566 2016] [:error] [pid 18858] apikey 4618d76f2fb84eacbac3339e5c7f2b57     [wed jan 27 13:35:05.868589 2016] [:error] [pid 18858] sig e8fe50c733ec6513c91f10caf63e7864     [wed jan 27 13:35:05.868608 2016] [:error] [pid 18858] con  81ew qewq166 

things recceived in request.post :-

 {             "_content_type": "application/json",             "_content": "{\"one\": \"9998889999\",\"con\": [7106174520, 8324100257]}\r\n"         } 

but when request.post.get('con') last element received ???

this 1 of funny things in django. if want list post request should use request.post.getlist(your_key). in case request.post.getlist('con').

you can find more topic here.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -