0

I'm in the process of connecting my React Native UI to Python Django backend using REST framework and unsure of how to go about fetching the data from backend.

I used the fetch(URL) as you can see in the SS below:

enter image description here

The error I get:

enter image description here

I also added my phone as an adb device and connected it through a USB cable before running the app, but same issue. Any suggestions as to how to go about React Native UI and Python Django REST API integration?

1 Answer 1

1

A bit late but I hope it will help the next ones.
You cannot use a regular url when connecting DRF (or any other API framework) to a react native app so you need to tunnel it through a reverse proxy such as ngrok. Short answer is, download ngrok, put it in your environment variable then in your shell type : ngrok http 8000 You will receive an https to replace your localhost:8000 in your API url. Good thing to do is to register to ngrok not to have to replace this new url too often, I think it is only stable for an hour or two if not registered. Last but not least, in your CORS config whitelist (CORS_ALLOWED_ORIGINS), don't forget to put this new url or you'll get a 404. Good luck

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.