Python 如何在cherrypy正常应用中跨域?

Python 如何在cherrypy正常应用中跨域?,python,cross-domain,cherrypy,Python,Cross Domain,Cherrypy,cherrypy.quickstart(HelloWorld()) 我执行跨域请求:未成功,然后在方法hello之前添加一个decorator(它在我的restful应用程序中成功工作),如下所示: class HelloWorld: @cherrypy.expose def hello(self): return "Hello World!" 浏览器会引发此异常: 选项500(内部服务器错误) 因为cherrypy找不到http方法“选项”。 但是如何让che

cherrypy.quickstart(HelloWorld())

我执行跨域请求:未成功,然后在方法hello之前添加一个decorator(它在我的restful应用程序中成功工作),如下所示:

class HelloWorld:
    @cherrypy.expose
    def hello(self):
        return "Hello World!"
浏览器会引发此异常: 选项500(内部服务器错误)

因为cherrypy找不到http方法“选项”。
但是如何让cherrypy自动发送选项请求?

看起来像是飞行前问题的重复。问问题之前你搜索过了吗?
def crossdomain(func):
    def decorate(*args, **kwargs):
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
        cherrypy.response.headers["Access-Control-Allow-Methods"] = "GET, POST, HEAD, PUT, DELETE"
        allow_headers = ["Cache-Control", "X-Proxy-Authorization", "X-Requested-With", "Content-Type"]
        cherrypy.response.headers["Access-Control-Allow-Headers"] = ",".join(allow_headers)
        return func(*args, **kwargs)
    return decorate

class HelloWorld:
    @cherrypy.expose
    @crossdomain
    def hello(self):
        return "Hello World!"

cherrypy.quickstart(HelloWorld())