Abe*_*sen 5 javascript django cross-domain cors overpass-api
我正在尝试在Django上运行的项目中使用带有JavaScript XMLHttpRequest 的立交桥API http://wiki.openstreetmap.org/wiki/Overpass_API,但我一直在使用
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.google.com/accounts/ClientLogin. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Run Code Online (Sandbox Code Playgroud)
错误.无论我是使用GET还是POST,还是来自任何其他主机,我都会收到此错误,而不仅仅是overpass API.
我已经安装了django-cors-headers https://github.com/ottoyiu/django-cors-headers并遵循那里的说明,将'corsheaders'放入INSTALLED_APPS,'corsheaders.middleware.CorsMiddleware','django.middleware .common.CommonMiddleware',进入MIDDLEWARE_APPS,我已经设置好了
CORS_ORIGIN_ALLOW_ALL = true
Run Code Online (Sandbox Code Playgroud)
在settings.py但似乎没有任何工作.我在本地运行它
python manage.py runserver
Run Code Online (Sandbox Code Playgroud)
但我也是在openshift上主持它.在这些工作中,他们都没有给出上述错误.
如果我在这里遗漏任何东西,请告诉我.
nik*_*k_m 10
我在尝试从笔记本电脑 ( )访问Heroku 上Django Rest Framework托管的 API时遇到了同样的问题。我正在使用,和.localhostDjango 1.10.2DRF 3.4.7python v3.4
我做了pip install django-cors-headers(版本 1.2.2)并按照文档说的进行了配置,然后再次出现相同的错误:(
继续搜索数小时,然后它击中了我!
我做pip install django-cors-middleware(1.3.1版本),不卸载的django-cors-headers包。另外我没有触及我settings.py文件中的任何东西(它被配置为django-cors-headers设置,尽管这两个包没有太多区别 - 后者是第一个的分支)。
点击刷新(来自本地主机),一切都运行良好!
我现在能够从myapp.herokuapp.comviajQuery的 ajax方法中获取数据。
小智 5
请记住将“corsheaders.middleware.CorsMiddleware”放在列表的顶部,并且“django.middleware.common.CommonMiddleware”已经是标准中间件
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Run Code Online (Sandbox Code Playgroud)
小智 5
CORS_ORIGIN_ALLOW_ALL = true
应该:
CORS_ORIGIN_ALLOW_ALL = True
T大写字母代表 True。添加额外所需的中间件
MIDDLEWARE = ['corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware', ]
Run Code Online (Sandbox Code Playgroud)
并将“corsheaders”注册到 INSTALLED_APPS。
| 归档时间: |
|
| 查看次数: |
6056 次 |
| 最近记录: |