Created
June 24, 2014 15:10
-
-
Save AnSavvides/b316f4ff7b454b381c12 to your computer and use it in GitHub Desktop.
Supporting jsonp with Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from flask import request, current_app | |
def support_jsonp(f): | |
"""Wraps JSONified output for JSONP""" | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
callback = request.args.get('callback', False) | |
if callback: | |
content = str(callback) + '(' + str(f().data) + ')' | |
return current_app.response_class(content, mimetype='application/json') | |
else: | |
return f(*args, **kwargs) | |
return decorated_function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment