How to solve Access to fetch at 'https://api.amadeus.com/v1/flight-offers' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. destinat

37 views
Skip to first unread message

Эля Min

unread,
Apr 21, 2024, 12:13:51 PMApr 21
to Django users
I have this one:from django.middleware.common import MiddlewareMixin
from django.http import JsonResponse

class CorsMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if request.method == "OPTIONS" and "HTTP_ACCESS_CONTROL_REQUEST_METHOD" in request.META:
            response = JsonResponse({"detail": "CORS policy allows this request"})
            response["Access-Control-Allow-Origin"] = "*"
            response["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
            response["Access-Control-Allow-Headers"] = "Content-Type, Authorization"
            return response
        return None

    def process_response(self, request, response):
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
        response["Access-Control-Allow-Headers"] = "Content-Type, Authorization"
        return response
AND:
CORS_ALLOWED_ORIGINS = [
BEFORE I DID PROXY,but my project stopped before starting. Please give me HElp
Reply all
Reply to author
Forward
0 new messages