2016-04-15 185 views
1

我试图将数据发布到我的Django服务器,但是当我检查服务器时,Querydict是空的。当我从浏览器中调用它看起来不错。Django发布请求数据

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 

回答

0

如果使用json说法,你应该通过你的字典原样,不要放弃它(docs):

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

data = json.dumps(有效载荷)或数据=有效载荷,在这两种情况下数据发送request.body – user1050619

+0

我的坏..问题是内容类型的标头..我必须将其作为JS删除打开或将其更改为多种形式的数据 – user1050619

0

如果您发送JSON请求,您需要使用request.body在django视图得到的,而不是request.POST