首页 > 编程语言 > 详细

【python】django上传文件

时间:2018-07-10 17:13:33      阅读:217      评论:0      收藏:0      [点我收藏+]

参考: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上传文件

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!