Django 与 Vue交互跨域问题解决
报错问题
Access to XMLHttpRequest at 'http://127.0.0.1:8000/apps03/student6/' from origin 'http://172.16.2.199:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
解决方法
pip install django-cors-headers
django
配置文件设置
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
......
'corsheaders',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
......
]
CORS_ORIGIN_WHITELIST = (
'http://172.16.2.199:8080',
)
CORS_ALLOW_CREDENTIALS = True
参考地址