1👍
Following these steps worked for me:
-
Install Django CORS
pip install django-cors-headers
-
Add it on INSTALLED_APPS (settings.py):
INSTALLED_APPS = [ ... 'corsheaders', ]
-
Add it on the top of MIDDLEWARE (settings.py):
MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', ... ]
-
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 )
-
Clear webbrowser cache (Empty Cache and Hard Reload – for chrome) and restart the application.
Source:stackexchange.com