安装CORS
pip install django-cors-headers
添加应用
INSTALLED_APPS = (
…
‘corsheaders’,
…
)
中间层设置
MIDDLEWARE = [
‘corsheaders.middleware.CorsMiddleware’,
…
]
添加白名单
CORS
CORS_ORIGIN_WHITELIST = (
‘127.0.0.1:8080’,
‘localhost:8080’,
‘www.meiduo.site:8080’,
‘api.meiduo.site:8000’
)
CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
凡是出现在白名单中的域名,都可以访问后端接口
CORS_ALLOW_CREDENTIALS 指明在跨域访问中,后端是否支持对cookie的操作。
######################################
Install nvm then install node.js,
nvm install node
then start the frontend service:
npm install -g live-server
get into the frontend server and start the website service:
live-server
then input url http://127.0.0.1:8080/