Site icon NgDeveloper

How to fix cross origin issue in python flask ?

Fixing cross origin issue in python flask is quiet easy and find the code snippet for the same below.

from flask import Flask, render_template, request, jsonify, redirect, url_for
import os, errno, subprocess
from flask_cors import CORS, cross_origin

os.path.realpath(__file__)
app = Flask(__name__)
app.config['SECRET_KEY']= 'some random text key like sdkfjsldfks dfksajdflksajdf sdfkjasdf'
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/slugs":{"origins":"http://localhost:port"}})


@app.route('/slugs', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type', 'Authorization'])
def getAllProgramTitlesAndSlugs():
	// your logic
	return  programs
Exit mobile version