Content negotiation

Content negotiation is the process of selecting one of multiple possible representations to return to a client, based on client or server preferences.

REST framework uses a simple style of content negotiation to determine which media type should be returned to a client, based on the available renderers, the priorities of each of those renderers, and the client's header. The style used is partly client-driven, and partly server-driven.

  • More specific media types are given preference to less specific media types.
  • application/json; indent=4
  • application/json, application/yaml and text/html

If the requested view was only configured with renderers for and HTML, then REST framework would select whichever renderer was listed first in the renderer_classes list or DEFAULT_RENDERER_CLASSES setting.

For more information on the HTTP Accept header, see


Note: "q" values are not taken into account by REST framework when determining preference. The use of "q" values negatively impacts caching, and in the author's opinion they are an unnecessary and overcomplicated approach to content negotiation.

This is a valid approach as the HTTP spec deliberately underspecifies how a server should weight server-based preferences against client-based preferences.


Custom content negotiation

REST framework's content negotiation classes handle selection of both the appropriate parser for the request, and the appropriate renderer for the response, so you should implement both the .select_parser(request, parsers) and methods.

The select_parser() method should return one of the parser instances from the list of available parsers, or None if none of the parsers can handle the incoming request.

The select_renderer() method should return a two-tuple of (renderer instance, media type), or raise a NotAcceptable exception.

The following is a custom content negotiation class which ignores the clientrequest when selecting the appropriate parser or renderer.

You can also set the content negotiation used for an individual view, or viewset, using the class-based views.