No 'Access-Control-Allow-Origin' Django
Posted 船长博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了No 'Access-Control-Allow-Origin' Django相关的知识,希望对你有一定的参考价值。
Access to XMLHttpRequest at \'http://127.0.0.1:8000/add\' from origin \'http://localhost:8080\' has been blocked by CORS policy: No \'Access-Control-Allow-Origin\' header is present on the requested resource.
Django框架Restangular发送API请求,跨源资源共享的问题。
解决方法:
pip install django-cors-headers
INSTALLED_APPS = (
...
\'corsheaders\',
...
)
MIDDLEWARE_CLASSES
= (
...
\'corsheaders.middleware.CorsMiddleware\',
\'django.middleware.common.CommonMiddleware\',
...
)
CORS_ORIGIN_ALLOW_ALL = True
注意
\'corsheaders.middleware.CorsMiddleware\', 需要在\'django.middleware.common.CommonMiddleware\',前面。
参考:
以上是关于No 'Access-Control-Allow-Origin' Django的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins打包报错:(No such file or directory) and 'parent.relativePath' points at no local POM
VS Code报错Module 'xx' has no 'xx' member pylint(no-member)解决办法
VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)
VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)