user1050619
user1050619

Reputation: 20856

Django post request data

Im trying to post data to my Django server but when I check the server the Querydict is empty. When I call from the browser it does look good.

import requests
import json
headers =  {
       "AUTHORIZATION": "1234",
       "Content-type": "application/json",
       "Accept": "text/plain"
    }
print headers    

payload = {
    "start_date_s":"04/01/2016",
    "start_date_e":"04/15/2016"
}


r = requests.post('http://localhost:8000/get-ticket-data',headers=headers, json = json.dumps(payload))
print r.content
print r.text

Upvotes: 1

Views: 1132

Answers (2)

ahmed
ahmed

Reputation: 5600

if you send json request, you need to use request.body in django view to get the that, not request.POST

Upvotes: 0

alecxe
alecxe

Reputation: 473753

If you use the json argument, you should pass your dict as is, don't dump it (docs):

r = requests.post('http://localhost:8000/get-ticket-data',headers=headers, json=payload)

Upvotes: 1

Related Questions