2016-08-22 82 views
0

我試圖讓我的django rest框架應用程序接受文件上傳。上傳文件應附帶描述文件的附加數據,並且對於後期處理是必要的。上傳文件似乎工作正常,但是,我似乎無法讓django應用程序訪問其他數據。例如,我有一個文件more_info.html而我試圖上傳到我的應用程序:Python - 將文件發佈到帶有額外數據的Django

import requests 

url = "http://www.example.com/fileupload" 
files = {'file':open('more_info.html','rb') 
data = {'brand':'my brand','type':'html','level':'dev'} 
headers = {'Content-type': 'multipart/form-data', 'Content-Disposition': 'attachment; filename="more_info.html"'} 
r = requests.post(url,files=files,data=,headers=headers) 

在我的Django的看法,我想用下面查看我的POST數據:

def post(self, request): 
    print(request.POST) 
    print(request.FILEs) 

兩個打印語句正在返回:

{u'file': <InMemoryUploadedFile: more_info.html (multipart/form-data)>} 

如何訪問請求POST中的其餘數據?

回答

0

此行

r = requests.post(url,files=files,data=,headers=headers) 

你似乎缺少分配數據給數據=。