js、ajax上传向服务器上传文件


def post(self, request): data = https://www.it610.com/article/{i: request.POST.get(i) for i in request.POST} for k, v in data.items(): if not v:del data[k] elif'date' in k:data[k] = parse(v).date() endswith = os.path.splitext(request.FILES.get('media').name)[-1] data['file_name'] = f'{uuid.uuid1()}{endswith}' with open(os.path.join('crawler', 'download', data['file_name']), 'wb') as wb: for i in request.FILES.get('media').chunks(): wb.write(i) wb.close()

    推荐阅读