I have just Found a simplest way to keep using django apis while working with react
step 1 -> just npm run your react project inside your react directory using
npm run start
you will see the development server starts at Local: at http://localhost:3000 by default
step 2 -> move to your django project directory and start your django server in another terminal
python manage.py runserver
this will start your django at http://127.0.0.1:8000/ by default
now whereever you are using axios or other bundles to fetch apis from django at the same port just add http://127.0.0.1:8000/ to the starting of their url
**you may now see an error that says cors header is not allowed from 3000 port but don't worry just few more steps **
step 3 -> go to your django directory and write
pip install django-cors-header
step 4 -> now go the setting files of the django project and make following changes as below :
INSTALLED_APPS = [
...
'corsheaders',
...
]
MIDDLEWARE=[
...
'corsheaders.middleware.CorsMiddleware',
...
]
CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
]
for thanks mark this answer useful! and for any query comment