zoukankan      html  css  js  c++  java
  • Django----解决跨域

    cors(跨域资源共享):

      本质设置响应头

     定制中间件 cors.py 后在settings.py中间件中配置

    from django.utils.deprecation import MiddlewareMixin
    
    class CORSMiddleware(MiddlewareMixin):
    
        def process_response(self,request,response):
            # 添加响应头
    
            # 允许你的域名来获取我的数据
            response['Access-Control-Allow-Origin'] = "*"
    
            # 允许你携带Content-Type请求头
            response['Access-Control-Allow-Headers'] = "Content-Type"
    
            # 允许你发送DELETE,PUT
            response['Access-Control-Allow-Methods'] = "DELETE,PUT"
    
            return response
    from django.utils.deprecation import MiddlewareMixin
    
    
    class CorsMiddleWare(MiddlewareMixin):
        def process_response(self, request, response):
            if request.method == 'OPTIONS':
                response['Access-Control-Allow-Headers'] = 'Content-Type'
                response['Access-Control-Allow-Method'] = 'POST,PUT,DELETE'
    
            response['Access-Control-Allow-Origin'] = '*'
    
            return response
    l

     https://www.cnblogs.com/liuqingzheng/articles/9794285.html?tdsourcetag=s_pcqq_aiomsg

  • 相关阅读:
    Pycharm
    Python
    navicat连接MySQL8.0出现2059错误
    MySQL Community Server 8.0.11下载与安装配置
    pip升级以及导入模块
    pycharm安装
    python环境安装
    js 超级玛丽(未完成)
    js 点名
    js 获取鼠标位置坐标
  • 原文地址:https://www.cnblogs.com/hanbowen/p/9900223.html
Copyright © 2011-2022 走看看