简体   繁体   中英

Django Rest Framework & React Js ( Axios API Request ): After Incorrect authentication attempt, api returns 400

I'm creating a login system and basically, I have two inputs, one for username and the other for password. So when the user enters the correct credentials the API returns 200 response with some data but after incorrect credentials the django-rest-framework marks the request as 400 Bad Request and returns the response with 400 status code and no data, but this happens only when I'm sending a request from react js, after trying bad credentials from postman, the API returns:

{
    "non_field_errors": [
        "Incorrect credentials"
    ]
} 

My Axios code:

 axios.post('http://192.168.0.29:8000/api/auth/login', {
      headers: {
        'Content-Type': 'application/json'
      },
      username: username,
      password: password
    })
    .then((response) => {
      console.log(response.data);
    })
    .catch(err => {
      console.log(err.data)
      alert('zjbs eroras')
    });

  }

我显示错误消息:

console.log(err.response.data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM