Django之CORF跨域请求设置

安装

pip install django-cors-headers

注册应用

INSTALLED_APPS = (
    ...
    'corsheaders',
    ...
)

注册中间件

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    ...
]

添加跨域请求白名单

# CORS
CORS_ORIGIN_WHITELIST = (
    '127.0.0.1:8080',
    '192.168.243.131:8080',
)
CORS_ALLOW_CREDENTIALS = True  # 允许携带cookie

你可能感兴趣的:(Django)