如何通过芹菜转换物体?

时间:2019-08-17 00:00:39

标签: django celery

我想用芹菜上传图片,但是有一些错误。

InMemoryUploadedFile类型的对象不可JSON序列化

请帮助我,非常感谢。

class UserViewSet(CusModelViewSet):
queryset = UserProfile.objects.all().order_by('-last_login')
serializer_class = UserSerializer
pagination_class = PageSet

def create(self, request, *args, **kwargs):
    data = request.data
    serializer = self.get_serializer(data=data)
    if serializer.is_valid():
        self.perform_create(serializer)
        image = data
        self.upload_files.delay(image)
        return json_response(serializer.data, status.HTTP_200_OK, '创建成功!')
    return json_response(serializer.errors, status.HTTP_400_BAD_REQUEST, get_error_message(serializer))
EncodeError at /get_data/users/
Object of type InMemoryUploadedFile is not JSON serializable
Request Method: POST
Request URL:    http://127.0.0.1:8000/get_data/users/
Django Version: 2.1.7
Exception Type: EncodeError
Exception Value:    
Object of type InMemoryUploadedFile is not JSON serializable
Exception Location: /usr/local/lib/python3.7/dist-packages/simplejson/encoder.py in default, line 273
Python Executable:  /media/morgan/project/develop/WebOnline/venv/bin/python

InMemoryUploadedFile类型的对象不可JSON序列化

1 个答案:

答案 0 :(得分:0)

您需要将blob转换为文本,然后才能将其传递给子进程