我尝试使用DRF保存图像。它保存但保存后作为响应我因为转义字符而收到断开的链接。
保存后的响应如下所示
{
"profilePic" : "http:\/\/127.0.0.1:8000\/media\/Images\/profilePic_MnPwLVh.jpg",
"user" : 31
}
我的序列化程序和视图
class ProfilePicCreateSerializer(ModelSerializer):
profilePic = serializers.ImageField(max_length=None, use_url=True)
class Meta:
model = ProfilePic
fields = [
'user',
'profilePic'
]
read_only_fields = ('user',)
class ProfilePicCreateAPIView(CreateAPIView):
queryset = ProfilePic.objects.all()
serializer_class = ProfilePicCreateSerializer
permission_classes = (IsAuthenticated,)
parser_classes = (MultiPartParser, FormParser,)
def perform_create(self, serializer):
serializer.save(user=self.request.user)
我能做些什么才能以正确的方式获取链接,而无需进行额外处理才能使用?