Skip to content

Instantly share code, notes, and snippets.

@davidadamojr
Last active June 22, 2021 13:17
Show Gist options
  • Save davidadamojr/465de1f5f66334c91a4c to your computer and use it in GitHub Desktop.
Save davidadamojr/465de1f5f66334c91a4c 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.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