Search code examples
djangopostdictionaryrequestdjango-piston

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


Solution

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