mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-07 09:23:43 +03:00
Updating docs
This commit is contained in:
parent
79715f01f8
commit
f95e7fae38
|
@ -74,37 +74,18 @@ If your API includes views that can serve both regular webpages and API response
|
||||||
|
|
||||||
Renders the request data into `JSON`, using utf-8 encoding.
|
Renders the request data into `JSON`, using utf-8 encoding.
|
||||||
|
|
||||||
Note that non-ascii characters will be rendered using JSON's `\uXXXX` character escape. For example:
|
Note that the default style is to include unicode characters, and render the response using a compact style with no uneccessary whitespace:
|
||||||
|
|
||||||
{"unicode black star": "\u2605"}
|
{"unicode black star":"★","value":999}
|
||||||
|
|
||||||
The client may additionally include an `'indent'` media type parameter, in which case the returned `JSON` will be indented. For example `Accept: application/json; indent=4`.
|
The client may additionally include an `'indent'` media type parameter, in which case the returned `JSON` will be indented. For example `Accept: application/json; indent=4`.
|
||||||
|
|
||||||
{
|
{
|
||||||
"unicode black star": "\u2605"
|
"unicode black star": "★",
|
||||||
|
"value": 999
|
||||||
}
|
}
|
||||||
|
|
||||||
**.media_type**: `application/json`
|
The default JSON encoding style can be altered using the `UNICODE_JSON` and `COMPACT_JSON` settings keys.
|
||||||
|
|
||||||
**.format**: `'.json'`
|
|
||||||
|
|
||||||
**.charset**: `None`
|
|
||||||
|
|
||||||
## UnicodeJSONRenderer
|
|
||||||
|
|
||||||
Renders the request data into `JSON`, using utf-8 encoding.
|
|
||||||
|
|
||||||
Note that non-ascii characters will not be character escaped. For example:
|
|
||||||
|
|
||||||
{"unicode black star": "★"}
|
|
||||||
|
|
||||||
The client may additionally include an `'indent'` media type parameter, in which case the returned `JSON` will be indented. For example `Accept: application/json; indent=4`.
|
|
||||||
|
|
||||||
{
|
|
||||||
"unicode black star": "★"
|
|
||||||
}
|
|
||||||
|
|
||||||
Both the `JSONRenderer` and `UnicodeJSONRenderer` styles conform to [RFC 4627][rfc4627], and are syntactically valid JSON.
|
|
||||||
|
|
||||||
**.media_type**: `application/json`
|
**.media_type**: `application/json`
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ A format string that should be used by default for rendering the output of `Date
|
||||||
|
|
||||||
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
||||||
|
|
||||||
Default: `None`
|
Default: `'iso-8601'`
|
||||||
|
|
||||||
#### DATETIME_INPUT_FORMATS
|
#### DATETIME_INPUT_FORMATS
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ A format string that should be used by default for rendering the output of `Date
|
||||||
|
|
||||||
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
||||||
|
|
||||||
Default: `None`
|
Default: `'iso-8601'`
|
||||||
|
|
||||||
#### DATE_INPUT_FORMATS
|
#### DATE_INPUT_FORMATS
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ A format string that should be used by default for rendering the output of `Time
|
||||||
|
|
||||||
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.
|
||||||
|
|
||||||
Default: `None`
|
Default: `'iso-8601'`
|
||||||
|
|
||||||
#### TIME_INPUT_FORMATS
|
#### TIME_INPUT_FORMATS
|
||||||
|
|
||||||
|
@ -309,6 +309,46 @@ Default: `['iso-8601']`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Encodings
|
||||||
|
|
||||||
|
#### UNICODE_JSON
|
||||||
|
|
||||||
|
When set to `True`, JSON responses will allow unicode characters in responses. For example:
|
||||||
|
|
||||||
|
{"unicode black star":"★"}
|
||||||
|
|
||||||
|
When set to `False`, JSON responses will escape non-ascii characters, like so:
|
||||||
|
|
||||||
|
{"unicode black star":"\u2605"}
|
||||||
|
|
||||||
|
Both styles conform to [RFC 4627][rfc4627], and are syntactically valid JSON. The unicode style is prefered as being more user-friendly when inspecting API responses.
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
#### COMPACT_JSON
|
||||||
|
|
||||||
|
When set to `True`, JSON responses will return compact representations, with no spacing after `':'` and `','` characters. For example:
|
||||||
|
|
||||||
|
{"is_admin":false,"email":"jane@example"}
|
||||||
|
|
||||||
|
When set to `False`, JSON responses will return slightly more verbose representations, like so:
|
||||||
|
|
||||||
|
{"is_admin": false, "email": "jane@example"}
|
||||||
|
|
||||||
|
The default style is to return minified responses, in line with [Heroku's API design guidelines][heroku-minified-json].
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
#### COERCE_DECIMAL_TO_STRING
|
||||||
|
|
||||||
|
When returning decimal objects in API representations that do not support a native decimal type, it is normally best to return the value as a string. This avoids the loss of precision that occurs with binary floating point implementations.
|
||||||
|
|
||||||
|
When set to `True`, the serializer `DecimalField` class will return strings instead of `Decimal` objects. When set to `False`, serializers will return `Decimal` objects, which the default JSON encoder will return as floats.
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## View names and descriptions
|
## View names and descriptions
|
||||||
|
|
||||||
**The following settings are used to generate the view names and descriptions, as used in responses to `OPTIONS` requests, and as used in the browsable API.**
|
**The following settings are used to generate the view names and descriptions, as used in responses to `OPTIONS` requests, and as used in the browsable API.**
|
||||||
|
@ -378,4 +418,6 @@ An integer of 0 or more, that may be used to specify the number of application p
|
||||||
Default: `None`
|
Default: `None`
|
||||||
|
|
||||||
[cite]: http://www.python.org/dev/peps/pep-0020/
|
[cite]: http://www.python.org/dev/peps/pep-0020/
|
||||||
|
[rfc4627]: http://www.ietf.org/rfc/rfc4627.txt
|
||||||
|
[heroku-minified-json]: https://github.com/interagent/http-api-design#keep-json-minified-in-all-responses
|
||||||
[strftime]: http://docs.python.org/2/library/time.html#time.strftime
|
[strftime]: http://docs.python.org/2/library/time.html#time.strftime
|
||||||
|
|
Loading…
Reference in New Issue
Block a user