Access to XMLHttpRequest at ' ' from origin ' ' has been blocked by CORS policy

Hi i am facing issue here 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',
   
]

Please identify what versions of Python, Django, and django-cors-headers you are using.

1 Like