Skip to content

Instantly share code, notes, and snippets.



Last active Oct 7, 2015
What would you like to do?
python decorator for bottle framework to enable CORS to an endpoint.
from bottle import Bottle,response
def allow_cors(func):
""" this is a decorator which enable CORS for specified endpoint """
def wrapper(*args, **kwargs):
response.headers['Access-Control-Allow-Origin'] = '' # * in case you want to be accessed via any website
return func(*args, **kwargs)
return wrapper
#example usages in an API endpoint
app = Bottle()
def get_cakes_by_id():
# loading cakes by ID
return {"cakes": cakes}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment