Zayyan Masud
Zayyan Masud

Reputation: 189

How to not escape characters in Django Rest Framework

I have a blog model. I have text field where I want to write in HTML, for example including an a tag. The permission class used on unsafe methods is isAdminUser. I don't necessarily have to escape the characters. Is there way where I could not escape the characters.

Upvotes: 0

Views: 1002

Answers (1)

Zayyan Masud
Zayyan Masud

Reputation: 189

This bit of code helped. I basically had to override to_representation.

def to_representation(self, instance):
    ret = super().to_representation(instance)
    ret['text'] = html.unescape(ret['text']) 
    return ret

Upvotes: 1

Related Questions