mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
Merge a13cdbeb25
into a251b93792
This commit is contained in:
commit
cfc012a102
|
@ -362,6 +362,16 @@ The default style is to return minified responses, in line with [Heroku's API de
|
||||||
|
|
||||||
Default: `True`
|
Default: `True`
|
||||||
|
|
||||||
|
#### SORTED_JSON
|
||||||
|
|
||||||
|
When set to `True`, keys in JSON responses will be sorted. For example:
|
||||||
|
|
||||||
|
{"email": "jane@example", "is_admin": false, "username": "jane"}
|
||||||
|
|
||||||
|
When set to `False`, the JSON responses are arbitrarily ordered.
|
||||||
|
|
||||||
|
Default: `False`
|
||||||
|
|
||||||
#### COERCE_DECIMAL_TO_STRING
|
#### 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 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.
|
||||||
|
|
|
@ -100,9 +100,12 @@ class JSONRenderer(BaseRenderer):
|
||||||
separators = INDENT_SEPARATORS
|
separators = INDENT_SEPARATORS
|
||||||
|
|
||||||
ret = json.dumps(
|
ret = json.dumps(
|
||||||
data, cls=self.encoder_class,
|
data,
|
||||||
indent=indent, ensure_ascii=self.ensure_ascii,
|
cls=self.encoder_class,
|
||||||
separators=separators
|
indent=indent,
|
||||||
|
ensure_ascii=self.ensure_ascii,
|
||||||
|
separators=separators,
|
||||||
|
sort_keys=api_settings.SORTED_JSON,
|
||||||
)
|
)
|
||||||
|
|
||||||
# On python 2.x json.dumps() returns bytestrings if ensure_ascii=True,
|
# On python 2.x json.dumps() returns bytestrings if ensure_ascii=True,
|
||||||
|
|
|
@ -110,6 +110,7 @@ DEFAULTS = {
|
||||||
# Encoding
|
# Encoding
|
||||||
'UNICODE_JSON': True,
|
'UNICODE_JSON': True,
|
||||||
'COMPACT_JSON': True,
|
'COMPACT_JSON': True,
|
||||||
|
'SORTED_JSON': False,
|
||||||
'COERCE_DECIMAL_TO_STRING': True,
|
'COERCE_DECIMAL_TO_STRING': True,
|
||||||
'UPLOADED_FILES_USE_URL': True,
|
'UPLOADED_FILES_USE_URL': True,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user