Issue with Django and Cross-Origin Request Blocked
i'm having issues with an API i have on docker it works with Django, I can access from other PCs on my network, however everytime i try to log in from any other PC that's not Mine i get the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/api/users/login. (Reason: CORS request did not succeed). Status code: (null).
Right now my code is like this:
`ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'django.middleware.common.CommonMiddleware',
]
CORS_ALLOWED_ORIGINS = [
'http://localhost:3001',
'http://localhost:3000',
'http://127.0.0.1:3001',
'http://127.0.0.1:3000',
]
CORS_ALLOW_CREDENTIALS = True`
I have tried Everything
CORS_ORIGIN_ALLOW_ALL = True
Doesn't work
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'http://localhost:3001',
)
Doesn't work Either
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
Doesn't work
I even tried
CORS_ALLOW_METHODS = (
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
)
according to the documentation on here