我想用芹菜上传图片,但有一些错误。
类型为"内存上传文件"的对象不可 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
类型为"内存上传文件"的对象不可 JSON 序列化
您需要将 blob 转换为文本,然后才能将其传递给子进程