Categories
Python Answers

How to solve cross origin resource sharing error with Flask and Python?

Spread the love

Sometimes, we want to solve cross origin resource sharing error with Flask and Python.

In this article, we’ll look at how to solve cross origin resource sharing error with Flask and Python.

How to solve cross origin resource sharing error with Flask and Python?

To solve cross origin resource sharing error with Flask and Python, we can use the flask-cors package.

To install it, we run

pip install -U flask-cors

Then we use it by writing

from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

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

to call CORS with app to enable CORS throughout the app.

Conclusion

To solve cross origin resource sharing error with Flask and Python, we can use the flask-cors package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *