Django跨域解決方法

from django.utils.deprecation import MiddlewareMixin

class Mymiddle(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

在settings中註冊中間件django

相關文章
相關標籤/搜索