Django CORS配置方案

参考

https://pypi.org/project/django-cors-headers/

在setting.py中设置

python 复制代码
INSTALLED_APPS = [
	......
	'corsheaders', #添加此行
]

MIDDLEWARE=[
	......
	'corsheaders.middleware.CorsMiddleware', #添加此行
	'django.middleware.common.CommonMiddleware',
	#'django.middleware.csrf.CsrfViewMiddleware',#注释此行
	......
]

#添加配置此白名单
#CORS_ALLOW_ALL_ORIGINS =TRUE
CORS_ALLOWED_ORIGINS = [
    "https://example.com",
    "https://sub.example.com",
    "http://localhost:8080",
    "http://127.0.0.1:9000",
]
CORS_ALLOW_METHODS = (
    "DELETE",
    "GET",
    "OPTIONS",
    "PATCH",
    "POST",
    "PUT",
)

CORS_ALLOW_HEADERS = (
    "accept",
    "authorization",
    "content-type",
    "user-agent",
    "x-csrftoken",
    "x-requested-with",
)
相关推荐
达梦产品与服务3 小时前
SQLark V4.4 更新 | 新增 SQL Server 数据库支持、自定义格式复制、Agent 辅助建表等 20+ 项功能已上线!
数据库
小Ti客栈5 小时前
MySQL 常用函数速查(完整篇)
数据库·mysql·adb
TomEval5 小时前
【测AI】第26篇:线上模型监控与告警体系 — 测试不是终点
人工智能·python·功能测试·ai
隔窗听雨眠5 小时前
高可用不止于数据库的全栈工程实践
数据库·架构设计·高可用
prince_zxill6 小时前
PEP 751 pylock.toml 实测:pip 26.3 装 6 个包版本全钉死,但 [web] 选不中任何东西
python·pip·依赖管理·pep 751
Thanks_ks8 小时前
Python 的垃圾回收——引用计数撑起日常,分代回收收拾残局
python·内存管理·垃圾回收·循环引用·引用计数·gc 模块·weakref
CyrusYiVPP8 小时前
实测 uv 0.13.7:同一套包,pip 装 94 秒,它只用 19 秒
人工智能·python
nice_lcj5208 小时前
MySQL 主从复制与读写分离:从库怎么跟着主库走
数据库·mysql·面试·binlog·读写分离·主从复制
yiangL_8 小时前
Python 学习笔记:递归、turtle绘图、字符串与函数
笔记·python·学习