Submitting files is a special case. To POST a file, you need only provide the file field name as a key, and a file handle to the file you wish to upload as a value. For example:
>>> c = Client()
>>> with open('test.jpg') as fp:
... c.post('/account/avatar_upload/',{
'avatar':fp})
测试文件上传其实没有什么特殊的,只需要指定后端接受请求数据的对应键值即可
(The name avatar here is not relevant; use whatever name your file-processing code expects.)在这里avatar是关联的,对应着具体的后端处理程序代码,eg:
class Useravatar(View):