0

I have the following curl, to pass a file to my url:

curl -F file=@/Users/david542/spreadsheet.xls  http://localhost:8000/spreadsheet

And in my view:

@csrf_exempt
def wb_spreadsheet(request):
    # how do I get the file??
    return HttpResponse('Hello!')

How do I get the file object to process here?

4

2 回答 2

0

它传入request.FILES——

@csrf_exempt
def wb_spreadsheet(request):
    file = request.FILES.get('file')
    return HttpResponse('Hello!')
于 2013-08-19T22:29:12.413 回答
0

引用文件上传文档

当 Django 处理文件上传时,文件数据最终放在 request.FILES 中。

利用:

request.FILES['file']
于 2013-08-19T22:30:46.957 回答