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

前端 未结 9 1129
臣服心动
臣服心动 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 18:00

    With the Flask-CORS module, you can do cross-domain requests without changing your code.

    from flask.ext.cors import CORS
    
    app = Flask(__name__)
    cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
    
    • https://pypi.python.org/pypi/Flask-Cors
    • https://github.com/corydolphin/flask-cors

    Update

    As Eric suggested, the flask.ext.cors module is now deprecated, you should rather use the following code:

    from flask_cors import CORS
    
    app = Flask(__name__)
    cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
    

提交回复
热议问题