# CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'http://localhost:9528',
'http://127.0.0.1:9528',
)
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'VIEW',
)
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
'x-token',
'X-Token',
)
Settings.py里面加上上面这些就可以了,特别是红色的
调试中发现的vue前端报错,“ ...blocked by CORS policy...”
网上查了一大堆,也在后台做了各种允许跨域的设置,都没用;最后发现vue用了一种叫X-Token的请求头,把这种请求头加到跨域的允许列表里就可以了