当前位置: 首页 > news >正文

前后台分离跨域交互

后台处理跨域

安装插件
>: pip install django-cors-headers插件参考地址:https://github.com/ottoyiu/django-cors-headers/
项目配置:dev.py
# 注册app
INSTALLED_APPS = [...'corsheaders',
]# 添加中间件
MIDDLEWARE = [...'corsheaders.middleware.CorsMiddleware',
]# 允许跨域源
CORS_ORIGIN_ALLOW_ALL = True# 允许的请求头
CORS_ALLOW_HEADERS = ("accept","accept-encoding","authorization","content-type","dnt","origin","user-agent","x-csrftoken","x-requested-with",# 额外允许的请求头'token',
)

前台请求Banner数据

修订Banner.vue
<template><div class="banner">
<!--        <el-carousel height="400px">-->
<!--            <el-carousel-item v-for="item in 4" :key="item">-->
<!--                <img src="../assets/img/banner1.png" alt="">-->
<!--            </el-carousel-item>-->
<!--        </el-carousel>--><el-carousel height="400px"><el-carousel-item v-for="banner in banner_list" :key="banner.title"><router-link :to="banner.link"><img :src="banner.image" alt=""></router-link></el-carousel-item></el-carousel></div>
</template><script>export default {name: "Banner",data() {return {banner_list: []}},// 在created钩子中created() {this.$axios({url: this.$settings.base_url + '/home/banners/',headers: {  // 测试前台给后台提交请求头// authorization: 'jwt abc.def.xyz',// token: 'jwt abc.def.xyz',}}).then(response => {console.log(response.data);this.banner_list = response.data;}).catch(error => {console.log(">>>", error);})}}
</script><style scoped>.el-carousel__item {height: 400px;min-width: 1200px;}.el-carousel__item img {height: 400px;margin-left: calc(50% - 1920px / 2);}
</style>
http://www.lryc.cn/news/290342.html

相关文章:

  • React16源码: React中处理LegacyContext相关的源码实现
  • Boost.Test资源及示例
  • 数据结构二叉树
  • JavaScript继承与原型链
  • SouthLeetCode-打卡24年01月第4周
  • Linux——磁盘和文件系统(一)
  • EasyCVR视频智能监管系统方案设计与应用
  • Ubuntu搭建国标平台wvp-GB28181-pro
  • LC 2808. 使循环数组所有元素相等的最少秒数
  • Qt|大小端数据转换
  • 禅道添加自定义字段
  • 蓝桥杯2024/1/26笔记-----基于PCF8591的电压采集装置
  • 【一】esp32芯片开发板环境搭建
  • PyTorch2ONNX-分类模型:速度比较(固定维度、动态维度)、精度比较
  • Docker命令快车道:一票通往高效开发之旅
  • IP类接口大全,含免费次数
  • LLMs 的记忆和信息检索服务器 Motorhead
  • vue3项目中让echarts适应div的大小变化,跟随div的大小改变图表大小
  • springboot启动异常
  • 直播主播之互动率与促单
  • Android 基础技术——Bitmap
  • 数据结构奇妙旅程之七大排序
  • 【JavaScript】Generator
  • 河南省考后天网上确认,请提前准备证件照哦
  • 【前端】防抖和节流
  • 【网络】:网络套接字(UDP)
  • Linux编程 1/2 数据结构
  • 【UE Niagara】实现闪电粒子效果的两种方式
  • js数组/对象的深拷贝与浅拷贝
  • HCIA学习第六天:OSPF:开放式最短路径优先协议