美文网首页
django vue nginx前后端分离(折腾)

django vue nginx前后端分离(折腾)

作者: 暮雨萧萧 | 来源:发表于2017-05-15 15:56 被阅读0次

安装

django

pip install django==1.9

nginx

sudo apt-get install nginx

vue

参考官网

<br />
需要解决几个问题
============

  1. 跨域请求问题:

No 'Access-Control-Allow-Origin' header is present on the requested resource.
解决办法:
安装 django-cors-headers
django配置:

CORS_ORIGIN_WHITELIST = (
 'google.com',
 'hostname.example.com',
 'localhost:8000',
 '127.0.0.1:8080',
 '127.0.0.1:8000',
 '0.0.0.0:8080'
)
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
)
  • 使用vue-resource 请求登录后无法set-cookie到cookie
    因为前后端分离后不同域无法在cookie中存入cookie,解决办法以下:
  • vue 设置proxyTable
  • nginx做url重写(只实践了这个)
    • 修改nginx.conf
        location /api {
            rewrite /api/?(.*)$  /$1 break;
            proxy_pass http://127.0.0.1:8000/;
        }
      
  • csrf

相关文章

网友评论

      本文标题:django vue nginx前后端分离(折腾)

      本文链接:https://www.haomeiwen.com/subject/oyshxxtx.html