Skip to main content

Flask-CORS is a simple extension to Flask allowing you to support cross origin resource sharing (CORS) using a simple decorator.

Build Status

Installation

Install the extension with using pip, or easy_install.

$ pip install flask-cors

Usage

This extension exposes a simple decorator to decorate flask routes with. Simply add @cross_origin() below a call to Flask’s @app.route(..) incanation to accept the default options and allow CORS on a given route.

Simple Usage

@app.route("/")
@cross_origin() # allow all origins all methods.
def helloWorld():
  return "Hello, cross-origin-world!"

Using JSON with Cross Origin

When using JSON cross origin, browsers will issue a pre-flight OPTIONS request for POST requests. In order for browsers to allow POST requests with a JSON content type, you must allow the Content-Type header.

@app.route("/user/create", methods=['GET','POST'])
@cross_origin(headers=['Content-Type']) # Send Access-Control-Allow-Headers
def cross_origin_json_post():
  return jsonify(success=True)

Application-wide settings

Alternatively, setting your application’s CORS_ORIGINS configuration property will

app.config['CORS_ORIGINS'] = ['Foo', 'Bar']


@app.route("/")
@cross_origin() # will return CORS headers for origins 'Foo' and 'Bar'
def helloWorld():
  return "Hello, cross-origin-world!"

For a full list of options, please see the full documentation

Tests

A simple set of tests is included in test.py. To run, install nose, and simply invoke nosetests or run python test.py or python setup.py test to exercise the tests.

Contributing

Questions, comments or improvements? Please create an issue on Github, tweet at [@wcdolphin](https://twitter.com/wcdolphin) or send me an email.

Bitdeli Badge

Release files for flask-cors 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-cors 1.3.1
File Size Uploaded
Flask-Cors-1.3.1.tar.gz 10.0 kB Details

Release files / Flask-Cors-1.3.1.tar.gz

Download URL Flask-Cors-1.3.1.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
351c1be901e7b16f533ad1c11ba7e86911270620ad7ec5f8c01b622d2b05f91a
BLAKE2b-256 checksum
How to use checksums
9971c1de3ad6a43c80156df35c7271567ac443ef747812b0d169b5c8e7f21c1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

6.0.5

2 release files

6.0.4

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.4

2 release files

3.0.3

3 release files

3.0.2

3 release files

3.0.1

3 release files

3.0.0

3 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.10.3

1 release file

1.10.2

3 release files

1.10.1

3 release files

1.10.0

3 release files

1.9.0

3 release files

1.8.1

3 release files

1.8.0

3 release files

1.7.4

3 release files

1.7.3

3 release files

1.7.2

3 release files

1.7.1

3 release files

1.7.0

3 release files

1.6.1

3 release files

1.6.0

3 release files

1.5.0

1 release file

1.4.0

1 release file

This release

1.3.1 This release

1 release file

1.3.0

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page