Django doesn't parse custom http accept header

Is there a way to allow a Django application to accept a custom acceptance header, such as "application / vdn.name.v1 + json"?

I get an answer like this

Could not satisfy the request Accept header. 

I also use Django Rest Framework

+5
source share
2 answers

Try defining your own renderer and set the media_type attribute.

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

Then turn on the renderer (see the docs for more information)

 REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( 'path.to.MyRenderer', 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ) } 
+1
source

Check out the Django Rest Framework JSON API. It formats responses in the JSON API format.

https://github.com/django-json-api/django-rest-framework-json-api

0
source

All Articles