Skip to content

Instantly share code, notes, and snippets.

@woosungchu
Forked from davidadamojr/server.py
Created September 7, 2016 09:23
Show Gist options
  • Select an option

  • Save woosungchu/f9cb92378a208bbbac54e74c653d71b0 to your computer and use it in GitHub Desktop.

Select an option

Save woosungchu/f9cb92378a208bbbac54e74c653d71b0 to your computer and use it in GitHub Desktop.
Accept CORS requests in Flask
from flask import Flask
from flask.ext import restful
from flask.ext.restful import Api
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('config')
#flask-sqlalchemy
db = SQLAlchemy(app)
#flask-restful
api = restful.Api(app)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
import views
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment