Enable CORS in a Backbone client with a Flask server Enable CORS in a Backbone client with a Flask server flask flask

Enable CORS in a Backbone client with a Flask server


Here is what worked for me.

http://flask-cors.readthedocs.org/en/latest/

$ pip install -U flask-cors

from flask import Flaskfrom flask.ext.cors import CORS, cross_originapp = Flask(__name__)cors = CORS(app)app.config['CORS_HEADERS'] = 'Content-Type'@app.route("/")@cross_origin()def helloWorld():  return "Hello, cross-origin-world!"


I got it working by adding

response.headers['Access-Control-Allow-Headers'] = "Origin, X-Requested-With,Content-Type, Accept" to the after_request() method.


For development you can:

Or just set Access-Control-Allow-Origin to *