后端: 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。