zoukankan      html  css  js  c++  java
  • Django serializer 中 将相对网址替换为绝对网址

    例子

    class GoodsSerializer(serializers.ModelSerializer):
        goods_desc = serializers.SerializerMethodField(help_text='内容', label='内容')
    
        def get_goods_desc(self, instance: Goods):
            goods_desc = instance.goods_desc.replace(
                    '<img src="' + MEDIA_URL,
                    '<img src="' + self.context['request'].build_absolute_uri(MEDIA_URL)
                    )
            return goods_desc
    
        class Meta:
            model = Goods
            fields = '__all__'
    
  • 相关阅读:
    js18
    js17
    js16
    js15
    js14
    js13
    js12
    js11
    八月二十三的php
    八月二十二的php
  • 原文地址:https://www.cnblogs.com/twfb/p/10858648.html
Copyright © 2011-2022 走看看