Python Flask Cors Issue

After I tried others suggestions and answers. Here’s what I use, which works.


  1. pip install flask flask-cors

  2. Copy and paste this in file


from flask import Flask, jsonify
from flask_cors import CORS, cross_origin

app = Flask(__name__)
CORS(app, support_credentials=True)

def login():
  return jsonify({'success': 'ok'})

if __name__ == "__main__":"", port=8000, debug=True)
  1. python

Note: be sure in your client’s ajax configuration has the following:

    type: "POST",
    data: {},
    dataType: 'json',
    xhrFields: {
       withCredentials: true
    crossDomain: true,
    contentType: 'application/json; charset=utf-8'

If one wonders, support_credentials=True just means it sends cookies along the payload back and forth.

Leave a Comment