【发布时间】:2014-11-02 05:12:36
【问题描述】:
周末 chrome 似乎已经更新,现在阻止了我的跨域请求:
我有一台服务器、两个域和一个需要在另一台上加载的共享网络图标字体。我宁愿不强迫cherrypy知道它服务于哪个域(镜像或主域),因为为此我不妨克隆所有代码。
我的 chrome console.log 错误信息是:
Font from origin 'http://djotjog.com' has been blocked from loading by Cross-Origin Resource Sharing policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://storylearning.org' is therefore not allowed access.
在cherrypy中,我尝试启用此功能,但文档很粗略。这是我尝试过的:
class root:
def stest(self, **kw):
cherrypy.response.headers['Content-Type'] = 'text/html'
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
html = some_function()
return html
def CORS():
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
if __name__=="__main__":
cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS)
cherrypy.config.update({
'environment': 'production',
'log.screen': False,
'log.error_file':'cperror.log',
'server.socket_host': '127.0.0.1',
'server.socket_port': 15722,
'server.thread_pool': 2,
'server.thread_pool_max': 2
那么在cherrypy上处理跨域请求的正确方式是什么?
【问题讨论】:
标签: python-2.7 cors cherrypy cross-domain-policy