【发布时间】:2017-11-18 09:37:38
【问题描述】:
我正在尝试接受使用基于 Django REST 函数的 POST API 发布的图像文件。这是基于https://github.com/m-haziq/django-rest-swagger-docs
我收到了这个错误截图 (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
这是我定义 API 的方式
@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
这是带有图像域的模型
class Employee(models.Model):
....
face_image = models.ImageField(upload_to='face_image/', blank=True)
有人可以告诉我正确的方法吗?处理帖子中的图像并将其保存到模型中。我的完整源代码在这些链接中。谢谢。
【问题讨论】:
标签: python django rest swagger imagefield