[Fixed]-Django Forms and Authentication with Front-end Framework (AngularJS/ReactJS)

1👍

First you have to develop API with Django-Rest-Framework.

Below is the minimal example how to send and receive data in ReactJs

submit data to api:

onSubmit(){
  fetch('https://djangoRest.com/endpoint/', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    firstParam: 'yourValue',
    secondParam: 'yourOtherValue',
  })
  })
}

ReactJs fetch data from API

loadData() {    
    fetch('https://djangoRest.com/endpoint/', {
            method: 'GET',
            headers: {
              'Accept': 'application/json',
              'Content-Type': 'application/json',
            }
          })
          .then((response) => response.json())
          .then((responseJson) => {
            if (responseJson.data) {
                this.setState({ Data: responseJson.data });
            }
            if (responseJson.errors) {
              console.log('errors', responseJson.errors)
            }
          })
    }

Ref:
https://facebook.github.io/react-native/docs/network.html

Leave a comment