Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django doesn't parse a custom http accept header

Is there any way to allow Django app to accept the custom accept header like "application/vdn.name.v1+json"?

I keep getting a response like this

Could not satisfy the request Accept header.

I am using Django Rest Framework as well

like image 235
masanorinyo Avatar asked Jun 17 '15 23:06

masanorinyo


1 Answers

Try defining a custom renderer and setting the media_type attribute.

from rest_framework.renderers import JSONRenderer

class MyRenderer(JSONRenderer):
    media_type = 'application/vdn.name.v1+json'

Then enable your renderer (see the docs for more info)

REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': (
        'path.to.MyRenderer',
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    )
}
like image 145
Alasdair Avatar answered Nov 04 '22 02:11

Alasdair