django解决跨域的问题
使用django-cors-headers库
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', #添加cors库中间件 'django.middleware.common.CommonMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
#settings中的配置
CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_METHODS=( 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', ) CORS_ALLOW_HEADERS=( 'accept-encoding', 'authorization', 'content-type', 'dnt', 'origin', 'user-agent', 'x-csrftoken', 'x-requested-with', )
NGINX代理解决跨域问题
用nginx代理服务器接收请求,然后再转发给真实的服务器
标签:跨域,middleware,django,问题,ALLOW,CORS,contrib From: https://www.cnblogs.com/powfu/p/16909950.html