[Python] Access to XMLHttpRequest at ' ' from origin ' ' has been blocked by CORS policy:...

Discussão em 'Python' iniciado por Stack, Fevereiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    Access to XMLHttpRequest at ' ' from origin ' ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    i am facing this issue while i am trying to host my project from vercel I got everything right in my settings.py file but got this error over and over while i tried to host my project from vercel . I am using

    django 5.1.6 django-cors-headers: 4.6.0 djangorestframework: 3.15.2

    i am also using react as my frontend framework. i also put this file as vercel.json in my backend directory but still got this error

    {
    “builds”: [
    {
    “src”: “backend/wsgi.py”,
    “use”: “@vercel/python”,
    “config”: { “maxLambdaSize”: “15mb” }
    }
    ],
    “routes”: [
    {
    “src”: “/(.*)”,
    “dest”: “backend/wsgi.py”
    }
    ]
    }


    this is my setting file please someone help me through this error

    CORS_ALLOW_ALL_ORIGINS =True

    ALLOWED_HOSTS = ["*"]
    INSTALLED_APPS = [

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'api',
    'corsheaders',
    'rest_framework',
    'rest_framework_simplejwt',
    ]

    MIDDLEWARE = [

    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    ]

    Continue reading...

Compartilhe esta Página