在邮差中拦截API时出现错误,如果我认为parser_classes会造成一些混乱



@detail_route(methods=['put'], parser_classes=[FileUploadParser])def avatar(self, request, pk=None):

file = request.data.get('file', None)
if not file:
print('f')
return Response(status=status.HTTP_400_BAD_REQUEST)
user = request.user
user.avatar_image.save(file.name, file)
user.save(update_fields={'avatar_image'})
generate_all_aliases(user.avatar_image, include_global=False)
return Response(AuthenticatedUserSerializer(request.user).data)

输入图片描述

尝试使用request. files .get()方法从request读取文件file = request.FILES.get('blogPhotos')

相关内容

  • 没有找到相关文章

最新更新