django 解决跨域问题

1、下载插件:

pip install django-cors-headers

2、在settings.py 中添加app:

'corsheaders'

3、在settings.py 中添加中间件:

'corsheaders.middleware.CorsMiddleware'

4、在settings.py 中配置允许跨站访问本站的地址:

CORS_ORIGIN_WHITELIST = ['http://localhost:8080']

5、在settings.py 中配置ALLOWED_HOSTS:

ALLOWED_HOSTS = ["192.168.78.241", "127.0.0.1"]

跨域详解:
https://github.com/adamchainz/django-cors-headers/blob/main/README.rst

posted @ 2022-04-20 11:54  随风飘-挨刀刀  阅读(140)  评论(0编辑  收藏  举报
Top