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‘,前面。 参考:
https://github.com/ottoyiu/django-cors-headers
https://www.cnblogs.com/allan-king/p/7094954.html