【Django】接收照片,储存文件 前端代码
发布时间:2020-12-15 17:08:59 所属栏目:大数据 来源:网络整理
导读:后端: from rest_framework.views import APIView from car settings from django.shortcuts render,redirect,HttpResponse from dal models from django.http JsonResponse os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath( __file__ ))) c
后端: from rest_framework.views import APIView from car settings from django.shortcuts render,redirect,HttpResponse from dal models from django.http JsonResponse os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) class Image(APIView): def post(self,request): file_obj = request.FILES.get('send',None) print("file_obj"file_path = os.path.join(BASE_DIR,'media','user/img',file_obj.name) file_pathw) as f: for chunk in file_obj.chunks(): f.write(chunk) message = {} message[code'] = 200 return JsonResponse(message) 前端ajax: <form method=post" action=/upload/" enctype=multipart/form-data" target=ifm1"> <input type="file" name="send"/> <input type=submit" value=Form表单提交"/> </form> ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |