Bottle Py: Enabling CORS for jQuery AJAX requests

前端 未结 4 1942
鱼传尺愫
鱼传尺愫 2020-11-28 08:40

I\'m working on a RESTful API of a web service on the Bottle Web Framework and want to access the resources with jQuery AJAX calls.

Using a REST client, the resource

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 09:27

    Consider letting your webserver, not Bottle, set the headers.

    Not sure whether this applies in your situation, but I've solved the problem in past projects by setting CORS headers for my Bottle application in Apache. It's easy to configure, keeps my Python code nice and clean, and is efficient.

    Information is available from many sources, but if you're using Apache, here's what my config looks like (more or less):

    
        Header set Access-Control-Allow-Headers "Origin, Content-Type"
        Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Request-Headers "Origin, Content-Type"
    
    

提交回复
热议问题