Django文檔(http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.post)說,要做到這一點:如何在Django測試中提交圖片上傳?
>>> c = Client()
>>> f = open('wishlist.doc')
>>> c.post('/customers/wishes/', {'name': 'fred', 'attachment': f})
>>> f.close()
但是,當我這樣做,現場有錯誤消息「提交的文件是空的。」這聽起來像一個PIL問題,但表格在實際網站上工作正常。
讀取文件併發送該文件而不是僅僅處理不起作用,其行爲與傳遞空字符串相同。
我希望你在/ doc中打開/打開票來修復這個例子;) – SmileyChris