Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created September 5, 2011 21:26
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pamelafox/1195953 to your computer and use it in GitHub Desktop.
Save pamelafox/1195953 to your computer and use it in GitHub Desktop.
CORS on Python/Flask
from flask import request, make_response,
def any_response(data):
ALLOWED = ['http://localhost:8888']
response = make_response(data)
origin = request.headers['Origin']
if origin in ALLOWED:
response.headers['Access-Control-Allow-Origin'] = origin
return response
@brianleroux
Copy link

gotta <3 flask

@nicolaiarocci
Copy link

Shouldn't the Access-Control-Allow-Origin response header be always included when there's an Origin header in the request?

@aaron-prindle
Copy link

Thank you very much for posting this!

@motdotla
Copy link

motdotla commented Mar 5, 2014

Thank you for posting this.

@vredchenko
Copy link

Thanks, this was a great time-saver!

@simonmelouah
Copy link

New to the concept of access-control-allow-origin, what does data take in? I assume it's the URL requesting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment