安装
django
pip install django==1.9
nginx
sudo apt-get install nginx
vue
参考官网
<br />
需要解决几个问题
============
- 跨域请求问题:
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/; }
- 修改nginx.conf
- csrf