to_json: use jsonp output if callback is present (#10127)
This commit is contained in:
parent
02f0c100de
commit
d4aca0571f
|
@ -48,7 +48,7 @@ class to_json(object):
|
|||
{
|
||||
"data": {
|
||||
"good": "bye"
|
||||
},
|
||||
},
|
||||
"err": 0
|
||||
}
|
||||
|
||||
|
@ -163,9 +163,10 @@ class to_json(object):
|
|||
|
||||
You can override the name of callback method using
|
||||
JSONRESPONSE_CALLBACK_NAME option or query arg callback=another_callback
|
||||
(in this case, format=jsonp if not specified)
|
||||
|
||||
>>> resp = users(requests.get('users',
|
||||
... { 'debug':1, 'format': 'jsonp', 'callback': 'my_callback' }))
|
||||
... { 'debug':1, 'callback': 'my_callback' }))
|
||||
>>> print resp.status_code
|
||||
200
|
||||
>>> print resp.content # doctest: +NORMALIZE_WHITESPACE
|
||||
|
@ -316,7 +317,10 @@ class to_json(object):
|
|||
debug = DEFAULT_DEBUG
|
||||
debug = debug or req.GET.get('debug', 'false').lower() in ('true', 't', '1', 'on')
|
||||
debug = debug or req.GET.get('decode', '0').lower() in ('true', 't', '1', 'on')
|
||||
format = req.GET.get('format', 'json')
|
||||
if 'callback' in req.GET:
|
||||
format = req.GET.get('format', 'jsonp')
|
||||
else:
|
||||
format = req.GET.get('format', 'json')
|
||||
jsonp_cb = req.GET.get('callback', CALLBACK_NAME)
|
||||
content_type = "application/json"
|
||||
|
||||
|
|
Loading…
Reference in New Issue