Skip to content

Set Multiple CORS Domains in Flask

homepage-banner

Here is a simple way to set multiple cross-origin resource sharing (CORS) domains in Flask.

Install Flask-Cors

pip install flask-cors

Set Multiple CORS domains

from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
CORS(app, resources={r"/": {"origins": ["Domain_1", "Domain_2"]}})

@app.route("/")
def hello():
    return "CORS-enabled web app!"

Reference

  • How to set multiple CORS domains in Flask (https://github.com/corydolphin/flask-cors/issues/212)
  • https://flask-cors.readthedocs.io/en/latest/
Small world. Big idea!
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • No personal information is collected
  • Made with Material for MkDocs and generative AI tools
  • Copyright issue feedback me#imzye.com, replace # with @
  • Get latest SRE news and discuss on Discord Channel