根据网上给出的教程实现这三者的联通之后,可能有些朋友会发现,跨域ajax 请求用不了 在 niginx 上配置了
location / { #add_header 'Access-Control-Allow-Origin' '*'; #add_header 'Access-Control-Allow-Credentials' 'true'; #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; #add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:9090;
}
也不管用,
原因在于django自身出于安全原因 ,设置了跨域限制,
在项目的settings.py中,
MIDDLEWARE_CLASSES 中有 django.middleware.csrf.CsrfViewMiddleware 这样一条数据,注释掉niginx 的跨域配置才会生效, 详细请搜索
CsrfViewMiddleware 的具体事项