Reputation: 589
I have the following POST request
curl -v --dump-header --H "Content-Type: application/json" -X POST --data '{"name": "John", "age": 27}' "http://localhost:8300/api/v1/create_contact?username=gegham&api_key=3efc6df6023534279d2183a696044a8cfec964a9"
Result after I'm printing request.POST is
POST:<QueryDict: {u'{"name": "John", "age": 27}': [u'']}>
but not
POST: <QueryDict: {u'name': [u'John'], u'age': [u'27']}>
So,I can't use this as dict and get values by keys. Why POST data format is difference from usual??
Upvotes: 1
Views: 2604
Reputation: 599480
Because you're sending JSON, not form data. Use request.body
and deserialize it with json.loads
.
Upvotes: 6