user5539903
user5539903

Reputation: 41

CORS headers not allowed in Django

I am developing an API in Django and using next js as the frontend. But each time I try to call the back end to the next js fronend I get on the console

Access to XMLHttpRequest at 'http://127.0.0.1:8000/' from origin 'http://0.0.0.0:3000' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space `local`

I also get this

Login error: 
AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
code
: 
"ERR_NETWORK"

I did the following

  1. I added to the first line of the middleware section 'corsheaders.middleware.CorsMiddleware', to my settings.py after install django cors headers
  2. Stopped and restarted the server
  3. I also ``` CORS_ALLOWED_ORIGINS = [ 'http://localhost:3000', 'http://127.0.0.1:3000', 'http://0.0.0.0:3000',

]

and yet i still get the problem

Upvotes: 0

Views: 86

Answers (1)

Vlad Marchenko
Vlad Marchenko

Reputation: 272

Have you done


INSTALLED_APPS = [
    ...,
    "corsheaders",
    ...,
]

?

Upvotes: 0

Related Questions