Frontend and backend are using different domain names, how to connect them?-CORS

安装CORS
pip install django-cors-headers
添加应用
INSTALLED_APPS = (

‘corsheaders’,

)
中间层设置
MIDDLEWARE = [
‘corsheaders.middleware.CorsMiddleware’,

]
添加白名单

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/

Or input $python3 -m http.server 8080

Original: https://blog.csdn.net/QQ_VV/article/details/121746933
Author: QQ_VV
Title: Frontend and backend are using different domain names, how to connect them?-CORS

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/734957/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球