【发布时间】:2019-02-09 15:46:30
【问题描述】:
我有一个具有以下 ImageField 类型的模型:
class Attendance(models.Model):
face_image = models.ImageField(, blank=True, null=True, storage=MediaStorage())
基于模型的序列化器
class AttendanceSerializer(serializers.ModelSerializer):
class Meta:
model = Attendance
fields = ('id','face_image')
但是如果 imagefield 为 null,则显示如下
Its now showing like this in the json
{
"id": 1,
"face_image": null
}
如果 face_image (ImageField) 为 None,它将显示输出为 null。我想要的是将 null 替换为像这样的空字符串 ""
【问题讨论】:
标签: python json django django-rest-framework