0
我试图接受一个图像文件已经发布使用我的基于POST API的Django REST函数。这是基于https://github.com/m-haziq/django-rest-swagger-docsDjango REST Swagger如何处理响应POST API(基于函数)
我收到此错误截图(https://imgur.com/a/ECq5y)
Object of type 'TypeError' is not JSON serializable
这样做
face_image = request.data.get('face_image')
和最新的正确的一步,将其保存到模型,这将是像这样的东西
employee.face_image = face_image
这里是我如何定义AP我
@api_view(['POST'])
def update_employee_image(request):
# ----- YAML below for Swagger -----
"""
description: This API deletes/uninstalls a device.
parameters:
- name: employee_id
type: integer
required: true
location: form
- name: face_image
type: file
required: true
location: form
"""
employee_id = request.POST.get('employee_id')
face_image = request.data.get('face_image') <--- this causes the error
这里是模型与ImageField的
class Employee(models.Model):
....
face_image = models.ImageField(upload_to='face_image/', blank=True)
有人可以让我知道这样做的正确方法?处理帖子中的图像并将其保存到模型中。我的完整源代码在这些链接中。谢谢。