Django Inbox Dictionaries

I make the following request through the cURL command line:

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 an answer. How can I access a sub-tier that I can then pass to ORM?

Thank,

Jamie

+3
source share
2 answers

HTTP data elements cannot have subelements. The data you posted - as shown in the querydict, has been interpreted as a single item with the key "place [name]" and the value "Starbucks". That way you can get it with request.POST["place[name]"].

+7

, , :

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

, "place = Starbucks", , , python script.

"-X POST", -d HTTP POST:

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

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

0

Source: https://habr.com/ru/post/1752880/


All Articles