Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS in Python Dash

I've seen that you can enable CORS for Flask (How to enable CORS in flask), but I have a Dash app and I want to enable something like

headers = { 'Access-Control-Allow-Origin':'*' }

Does anyone know how to do it?

like image 982
RLC Avatar asked Dec 02 '25 22:12

RLC


1 Answers

You can enable CORS on Dash by using flask_cors

Here a snippet you could try:

import dash
from flask_cors import CORS

app = dash.Dash(__name__)
server = app.server
CORS(server)

@app.route("/")
def helloWorld():
  return "Hello, cross-origin-world!"

At this link https://flask-cors.readthedocs.io/en/latest/ you can find the documentation for the Flask-CORS library with instructions regarding how to install and configure it

like image 156
Marco Avatar answered Dec 04 '25 12:12

Marco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!