Django post request data

时间:2016-04-15 15:16:41

标签: python django python-requests

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

2 个答案:

答案 0 :(得分:0)

如果使用json参数,则应按原样传递dict,不要转储它(docs):

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

答案 1 :(得分:0)

如果你发送json请求,你需要在django视图中使用request.POST来获取它,而不是AES_encrypt