class Base(object): def postData(self, res): ''' 這是根據查看django裏的request.post源碼發現的 這裏請求發數據發送給django後用request.post請求的話請求頭須要是 header: content - type: application / x - www - form - urlencoded才能夠接受到.通常會攜帶在瀏覽器請求頭裏 content-type: application/json,json的格式request.post是接受不到的,只有在request.body才能夠得到數據 ''' # requests.post(settings.API_URL, data=json.dumps(res)) # 下面與上面的方式相等,進行了優化簡寫 requests.post(settings.API_URL, json=res)
截圖django裏的request.post源碼截圖django