Giter VIP home page Giter VIP logo

react-native-with-django-rest's Introduction

React Native with Django REST Framework

Integrate your React Native Mobile App frontend with Django Rest Framework backend with REST APIs

Backend:

Install the django-cors-headers package:

pip install django-cors-headers

Add 'corsheaders' and 'api' to your INSTALLED_APPS in your project's settings.py:

image

Add 'corsheaders.middleware.CorsMiddleware' to your MIDDLEWARE in settings.py. It should be placed after CommonMiddleware:

image

Configure CORS settings in settings.py.

Allow all origins and methods

Type ipconfig in command prompt and put the IPV4 address from under the 'Wireless LAN adapter Wi-Fi' section to allowed hosts

image

Ensure that your Django development server is running and listening on the correct IP address (0.0.0.0) to accept connections from devices on the local network:

python manage.py runserver 0.0.0.0:8000

The main advantage of using 0.0.0.0 is that it enables you to access the development server from other devices on your local network, such as your React Native app running on a different device or emulator/simulator. This can be very useful for testing and development, as it allows you to see how your app behaves when interacting with the server from different devices. Ensure that your firewall and security settings are configured to allow incoming connections on this port if you want to access the server from devices other than the one running the server.

Frontend:

Create a React Native App:

npx create-expo-app frontend

Download the Expo Go app and scan the QR code

Install axios for fetching data from Django REST

npm install axios

Type ipconfig in command prompt and put the IPV4 address from under the 'Wireless LAN adapter Wi-Fi' section with port 8000 as the base URL with endpoint '/students/' to get the list of all students

image

Display the list using the map() function

image

Output on mobile device

image

react-native-with-django-rest's People

Contributors

siddhantkodolkar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.