python使用cors解决跨域问题

 下载跨域

pip install django-cors-headers

在INSTALLED_APPS里面输入

'corsheaders',

在MIDDLEWARE添加中间件 放到第三行

'corsheaders.middleware.CorsMiddleware',

CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = ()
# 对应的发送的请求的跨域
CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    'VIEW',
)

CORS_ALLOW_HEADERS = (
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
)

猜你喜欢

转载自blog.csdn.net/Z_Gleng/article/details/129878167