views:

30

answers:

2

I'm making the following request through command-line cURL:

curl -X POST http://localhost:8000/api/places/ -vvvv -d "place[name]=Starbucks"

However, when I try to access the parameters by calling

request.POST.getlist('place')

I get an empty array as a response. How can I access the sub-dictionary which I can then pass to the ORM?

Thanks,

Jamie

+3  A: 

HTTP data elements can't have sub-elements. The data you have posted - as shown in the querydict - has been interpreted as a single element with key "place[name]" and value "Starbucks". So you can get it with request.POST["place[name]"].

Daniel Roseman
Ahh, that's what I was afraid of. Thanks. I'm coming from a PHP background so I'm used to $_POST['place']['name']. Thanks!
Jamie Rumbelow
A: 

It looks like you are sending a string, in that case try:

request.POST.get('place[name]')

If your are simulating a dropdown list you should send "place=Starbucks", however if you are trying to send an array you should try to convert you string to an array inside your python script.

In your command you can get ride of "-X POST" as the parameter -d is already an HTTP POST:

curl --help
...
-d/--data <data>   HTTP POST data (H)

curl manual: http://curl.haxx.se/docs/manual.html

ee_vin