C D
C D

Reputation: 223

React Native and Django Rest Framework connection problem at local,Cors settings

I am building a react native project. I have already done the same project's website. I deployed it on Heroku and without any problem it works. When I try to fetch data on local server with react native app, It does not work but when I use deployed project url it works.

For example;

http://127.0.0.1:8000/api/sosyalmedya/ does not work.

http://mydeployedwebsite.com/api/sosyalmedya/ work.

My settings.py is the same with deployed one.

In my settings.py I have added these;

ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True

Edit!!! There is no problem with React. The problem occurs when I try to fetch data in React Native

Upvotes: 0

Views: 559

Answers (1)

C D
C D

Reputation: 223

I solved this problem just replacing localhost url. In React Native,as I saw, we have to change localhost url to 10.0.2.2 to fetch data. In my case; http://10.0.2.2:8000/api/sosyalmedya/ worked.

Upvotes: 2

Related Questions