From 648d2be29b0738999742f4d844caab7b7652d1ad Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 10 Oct 2012 12:15:18 +0100 Subject: Make sure JSON output in Browseable API is nicely indented --- docs/api-guide/renderers.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'docs/api-guide/renderers.md') diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index 1b266f7e..b2ebd0c7 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -132,7 +132,7 @@ Renders data into HTML for the Browseable API. This renderer will determine whi ## Custom renderers -To implement a custom renderer, you should override `BaseRenderer`, set the `.media_type` and `.format` properties, and implement the `.render(self, data, media_type)` method. +To implement a custom renderer, you should override `BaseRenderer`, set the `.media_type` and `.format` properties, and implement the `.render(self, data, media_type=None, renderer_context=None)` method. For example: @@ -144,11 +144,26 @@ For example: media_type = 'text/plain' format = 'txt' - def render(self, data, media_type): + def render(self, data, media_type=None, renderer_context=None): if isinstance(data, basestring): return data return smart_unicode(data) +The arguments passed to the `.render()` method are: + +#### `data` + +The request data, as set by the `Response()` instantiation. + +#### `media_type=None` + +Optional. If provided, this is the accepted media type, as determined by the content negotiation stage. Depending on the client's `Accept:` header, this may be more specific than the renderer's `media_type` attribute, and may include media type parameters. For example `"application/json; nested=true"`. + +#### `renderer_context=None` + +Optional. If provided, this is a dictionary of contextual information provided by the view. +By default this will include the following keys: `view`, `request`, `response`, `args`, `kwargs`. + --- # Advanced renderer usage -- cgit v1.2.3