[Answered ]-Django backend wont accept get requests from my front end

1👍

Following these steps worked for me:

  1. Install Django CORS

    pip install django-cors-headers
    
  2. Add it on INSTALLED_APPS (settings.py):

    INSTALLED_APPS = [
        ...
        'corsheaders',
    ]
    
  3. Add it on the top of MIDDLEWARE (settings.py):

    MIDDLEWARE = [
        'corsheaders.middleware.CorsMiddleware',
        ...
    ]
    
  4. The CORS variable can be this way (settings.py):

    CORS_ORIGIN_ALLOW_ALL = True
    # or: 
    CORS_ORIGIN_ALLOW_ALL = False
    CORS_ORIGIN_WHITELIST = (
      'http://localhost:3000', # or the reactjs address being used
    )
    
  5. Clear webbrowser cache (Empty Cache and Hard Reload – for chrome) and restart the application.

👤Helder

Leave a comment