How to enable CORS in python

前端 未结 2 2001
感动是毒
感动是毒 2021-01-23 06:23

Let me start this with, I do not know python, I\'ve had maybe 1 day going through the python tutorials. The situation is this. I have an angular app that has a python app host

2条回答
  •  离开以前
    2021-01-23 07:14

    Here it is. Just add this to the application right at the beginning:

    def application(environ, start_response):
      if environ['REQUEST_METHOD'] == 'OPTIONS':
        start_response(
          '200 OK',
          [
            ('Content-Type', 'application/json'),
            ('Access-Control-Allow-Origin', '*'),
            ('Access-Control-Allow-Headers', 'Authorization, Content-Type'),
            ('Access-Control-Allow-Methods', 'POST'),
          ]
        )
        return ''
    

提交回复
热议问题