• contenttype组件和跨域问题笔记


    跨域
            浏览器的同源策略
                -- 阻止ajax请求不阻止src请求
            JsonP 解决跨域的方式
            添加响应头
                -- 简单请求和复杂请求
                    简单请求满足:
                        HTTP方法是下列方法之一
    
                      HEAD, GET,POST
    
                    HTTP头信息不超出以下几种字段
    
                      Accept, Accept-Language, Content-Language, Last-Event-ID
    
                      Content-Type只能是下列类型中的一个
    
                        application/x-www-from-urlencoded
    
                        multipart/form-data
    
                        text/plain
                -- 复杂请求
                    -- 先发送预检请求 OPTIONS
                -- 写一个中间件
                    class MyCors(MiddlewareMixin):
                        def process_response(self, request, response):
                            response["Access-Control-Allow-Origin"] = "*"
                            if request.method == "OPTIONS":
                                # 复杂请求会先发预检
                                response["Access-Control-Allow-Headers"] = "Content-Type"
                                response["Access-Control-Allow-Methods"] = "PUT,PATCH,DELETE"
                            return response
                            
        ContentType组件
            -- 一张表跟多张表创建外键关系的时候
            --  content_type = models.ForeignKey(to=ContentType)
                到ContentType 定位到表
                object_id = models.IntegerField()
                # 定位到对象id
                content_object = GenericForeignKey("content_type", "object_id")
                # 不会生成字段 只用于关联到对象的
            
  • 相关阅读:
    斐波那契数列 的两种实现方式(Java)
    单链表反转
    单链表合并
    两个有序list合并
    list去重 转载
    RemoveAll 要重写equals方法
    Java for LeetCode 138 Copy List with Random Pointer
    Java for LeetCode 137 Single Number II
    Java for LeetCode 136 Single Number
    Java for LeetCode 135 Candy
  • 原文地址:https://www.cnblogs.com/bozhengheng/p/12121709.html
Copyright © 2020-2023  润新知