Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django POST sub-dictionaries

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

like image 337
Jamie Rumbelow Avatar asked Sep 13 '26 17:09

Jamie Rumbelow


1 Answers

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]"].

like image 87
Daniel Roseman Avatar answered Sep 16 '26 08:09

Daniel Roseman