【发布时间】:2018-04-05 10:07:04
【问题描述】:
这是我的models.py:
models.py
class Resource(Document):
instruction = fields.StringField(required=True)
picture = fields.ImageField(required=False)
还有我的序列化器:
class ResourceSerializer(serializers.DocumentSerializer):
class Meta:
model = Resource
fields = '__all__'
还有我的观点.py
class ResourceViewSet(viewsets.ModelViewSet):
lookup_field = 'id'
serializer_class = ResourceSerializer
def get_queryset(self):
return Resource.objects()
这是我在尝试列出图片时得到的响应
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
[
{
"id": "5ac4886a91a48946801813c9",
"instruction": "test",
"picture": "5ac4886991a48946801813bf"
}
]
注意:mongodb 使用 gridfs 存储图像文件
如果 mongodb 使用 gridfs 存储图像文件,我如何将图像发送到客户端?
【问题讨论】:
标签: python django mongodb django-rest-framework mongoengine