码迷,mamicode.com
首页 > 编程语言 > 详细

【python】django上传文件

时间:2018-07-10 17:54:58      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:csdn   return   ons   files   示例   ocs   bsp   django 视图   loaded   

参考:https://blog.csdn.net/zahuopuboss/article/details/54891917

参考:https://blog.csdn.net/zzg_550413470/article/details/51538814

参考:https://www.cnblogs.com/linxiyue/p/7442232.html

django 文件存储:https://docs.djangoproject.com/en/dev/ref/files/storage/

django 视图接收:https://docs.djangoproject.com/en/dev/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile

 

示例代码:

def upload_view(request):
    file_object = request.FILES.get(f,‘‘)
    print file name:, file_object.name, file size:, file_object.size, file content_type:, file_object.content_type
    if file_object:
        storage_system_object = get_storage_class()(settings.BASE_DIR + /filestorage/)
        upload_file_object = ContentFile(content = file_object.read(), name = file_object.name)
        storage_system_object.save(name = file_object.name, content = upload_file_object)
    return HttpResponse(json.dumps({status:200, info:""}))

 

上传:

curl http://projecturl/path/ -F "f=@uploadfile"

 

【python】django上传文件

标签:csdn   return   ons   files   示例   ocs   bsp   django 视图   loaded   

原文地址:https://www.cnblogs.com/jiangxu67/p/9290067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!