2015-07-03 119 views
3

我看到的Javascript控制台上出现以下错误:如何在Google App Engine Python服务器上启用CORS?

VM31:1 XMLHttpRequest cannot load '<some-url>'. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<my-url>' is therefore not allowed access. 

如何启用跨来源资源共享与谷歌的App Engine(Python)的访问?

+0

是一个静态文件,还是你用python代码处理的东西?杰弗瑞的答案涵盖了第一种情况... – Greg

回答

3

你将不得不使用Access-Control-Allow-Origin HTTP标头在你的YAML配置

handlers: 
- url:/
    ... 
    http_headers: 
    Access-Control-Allow-Origin: http://my-url 

查找CORS支持下,多在docs

+0

这只适用于'static_dir'(静态应用程序) – eMarine

+1

如何为整个应用程序做?什么应该提供static_dir – anshulix

+0

@anshulix我不知道我遵循你问的问题。谨慎阐述? –

2

对于Python脚本可以添加邻近自以下行.response.header行。

self.response.headers['Access-Control-Allow-Origin'] = '*' 

这对我有效。这个想法是从另一个答案的注释中列出的PHP问题。

相关问题