Django Rest Framework Doesn't escape Html Entity Problem [closed]

余生长醉 提交于 2020-06-01 07:41:26

问题


I wrote the django blog and api.

When i started the postman and then wrote the api url it returns correct values except content i have issue with content content is returning &ouml . It's turkish charset &ouml=ö How can i fix this problem ?

api/serializers.py:

class MakaleSerializer(serializers.ModelSerializer):
    Yazar = serializers.CharField(source="Yazar.username")
    class Meta:
        model = Makale
        fields = ('__all__')
    def to_representation(self, instance):
        data = super().to_representation(instance)
        data['İçerik'] = strip_tags(instance.İçerik)
        return data 

api/views.py:

class MakaleRudView(APIView):
   def get(self, request):
       makale = Makale.objects.all()
       serializer = MakaleSerializer(makale , many=True)
       return Response(serializer.data)

and the postman or drf(Django Rest Framework returns :

    {
        "id": 26,
        "Yazar": "gorkem",
        "Başlık": "Atatürk'ün Samsuna Çıkışı 2",
        "İçerik": "Atatürk'ün Samsuna çıkışı sırasında Türkiye Cumhuriyeti'nin",
        "Olusturma_Tarihi": "2020-05-29T09:10:43.874477+03:00",
        "makal_resim": null
    },

来源:https://stackoverflow.com/questions/62081405/django-rest-framework-doesnt-escape-html-entity-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!