Where do I define the Content-Type I want to receive in my Django API?

Viewed 123

I have a Django app that only needs to receive requests with Content-Type: text/plain. Is there an option for that when using the GenericViewSet?

1 Answers

I had to write my own Parser for plain text (in my case, the body contains json although the Content-Type is plain text, so I just had to override media_type) like this:

class PlainTextParser(JSONParser):
    media_type = "text/plain"

and use it in my ViewSet like this:

parser_classes = [PlainTextParser]
Related