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

前端 未结 9 1109
臣服心动
臣服心动 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:02

    You can use the after_request hook:

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
        response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
        return response
    

提交回复
热议问题