Added function 'padded_jsonify' to return JSONP
This commit is contained in:
parent
6e3dd9b3ce
commit
5fad5473e2
2 changed files with 6 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ from jinja2 import Markup, escape
|
|||
|
||||
from .app import Flask, Request, Response
|
||||
from .config import Config
|
||||
from .helpers import url_for, jsonify, json_available, flash, \
|
||||
from .helpers import url_for, jsonify, padded_jsonify, json_available, flash, \
|
||||
send_file, send_from_directory, get_flashed_messages, \
|
||||
get_template_attribute, make_response
|
||||
from .globals import current_app, g, request, session, _request_ctx_stack
|
||||
|
|
|
|||
|
|
@ -99,6 +99,11 @@ def jsonify(*args, **kwargs):
|
|||
return current_app.response_class(json.dumps(dict(*args, **kwargs),
|
||||
indent=None if request.is_xhr else 2), mimetype='application/json')
|
||||
|
||||
def padded_jsonify(*args, **kwargs):
|
||||
if __debug__:
|
||||
_assert_have_json()
|
||||
content = str(callback) + '(' + json.dumps(dict(*args, **kwargs)) + ')'
|
||||
return current_app.response_class(content, mimetype='application/json')
|
||||
|
||||
def make_response(*args):
|
||||
"""Sometimes it is necessary to set additional headers in a view. Because
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue