[django]django配合前端vue前后端联调,django服务端解决跨域(django-cors-headers)
2024-10-02 04:33:09
django内部csrf post提交数据解决
https://www.cnblogs.com/iiiiiher/articles/9164940.html
前端写了个页面,里面$.post发现403错误. 需要注释下
前后端联调的跨域问题
前端可能是127.0.0.1:3000 后端127.0.0.1:8080
导致前端不能正常访问
https://github.com/ottoyiu/django-cors-headers
安装配置
pip install django-cors-headers
INSTALLED_APPS = (
...
'corsheaders',
...
)
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
配置
- 全局设置为true
CORS_ORIGIN_ALLOW_ALL = True
- 指定白名单
CORS_ORIGIN_WHITELIST = (
'google.com',
'hostname.example.com',
'localhost:8000',
'127.0.0.1:9000'
)
- reg匹配域名
- 限制方法
最新文章
- 简单排序,C# 直接使用 List。
- Spark Streaming消费Kafka Direct方式数据零丢失实现
- Halcon 10.0:Sample 分割边缘拟合圆Circles.hdev
- ubuntu 命令行软件包管理
- 解决Socket.IO在IE8下触发disconnect时间过长
- UIViewController中各方法调用顺序及功能详解
- less学习-语法(二)
- quartz简单实现
- photoshopcs5 win7安装报错的解决
- 3 Sum Closest 解答
- Jar包转成Dll的方式(带嵌套的jar也能做) (转)
- ubuntu环境下lnmp环境搭建(1)之Mysql
- nodejs爬虫笔记(一)---request与cheerio等模块的应用
- luogu P1602 Sramoc问题
- numpy的random模块
- appium使用错误集合
- SpringMVC异常处理注解@ExceptionHandler@ControllerAdvice@ResponseStatus
- Android7.0对dlopen的改变——读取私有.so结果变化
- [原]IOS 后台发送邮件
- SOALog
热门文章
- 史上最简洁的UITableView Sections 展示包含NSDicionary 的NSArray
- 关于linux Centos 7一个网卡配置多个IP的方法
- iOS动画篇:核心动画
- python 读取配置文件方法
- day_5.11 py main
- 引用了System.Configuration命名空间,却找不到ConfigurationManager类
- J - Vertical Histogram(1.5.7)
- DB2 性能分析工具介绍:Event Monitor 篇(转)
- 2018ACM-ICPC南京区域赛M---Mediocre String Problem【exKMP】【Manacher】
- win server 2008添加磁盘-脱机转换为联机状态方法