Flask RESTful cross-domain issue with Angular: PUT, OPTIONS methods

前端 未结 9 1114
臣服心动
臣服心动 2020-12-12 17:14

I\'ve developed a small write-only REST api with Flask Restful that accepts PUT request from a handful of clients that can potentially have changing IP addresses. My clients

9条回答
  •  旧巷少年郎
    2020-12-12 17:43

    To allow remote CORS requests on your web service api, you can simply initialize your flask restful API like this:

    from flask import Flask
    from flask_restful import reqparse, abort, Api, Resource
    from flask_cors import CORS
    
    app = Flask(__name__)
    cors = CORS(app, resources={r"*": {"origins": "*"}})
    api = Api(app)
    

    This adds the CORS header to your api instance and allows a CORS request on every path from every origin.

提交回复
热议问题