2013-07-27 14 views
0

在Django中,request.META中有很多東西,我的當前代碼在request.META中檢查HTTP_TOKEN之類的東西,所以當發送請求時,我需要發送請求到該URL,以便在接收服務器中,數據出現在request.META中。django - request.META - 在發送請求時,如何處理以使數據顯示在請求中.META

我覺得頭出現在那裏,所以我想這:

python example:(I am sending request from javascript, but getting it work from any client is enough so I can implement finally using javascript). 
    r = requests.get(url, headers={'HTTP_TOKEN': 'abc'}) 

但是從收到請求後,我沒有找到request.META像HTTP_TOKEN東西。

回答

1

With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.

https://docs.djangoproject.com/en/dev/ref/request-response/

所以,你的情況,我認爲你需要簡單地發送{"TOKEN": "abc"}

+0

謝謝,工作:) – user1305989

相關問題