我有一个应用程序,其中React作为前端,而django rest框架作为后端,我使用axios发送我的响应,但是数据为空

时间:2019-04-25 18:16:58

标签: django reactjs django-rest-framework axios django-allauth

我有一个带有react和Django rest框架的应用程序。我使用Django allauth进行登录和注册。当我要登录时,一切正常,响应为201,但数据为空,我没有获得令牌。我与邮递员发送了此请求,并获得了令牌。我该怎么办?

反应请求:

axios({
  method: 'post',
  url: 'http://localhost:8000/rest-auth/login/',
  data: {
    username: 'admin',
    email: '',
    password: 'admin123456'
  },
  headers: { 'content-type': 'application/json' }
})
  .then(response => {
    console.log(response.data.key);
  })
  .catch(error => {
    console.log(error);
  });

响应为:

{data: "", status: 200, statusText: "OK", headers: {…}, config: {…}, …}

邮递员请求:http://localhost:8000/rest-auth/login/

{
    "username": "mahtab",
    "email": "",
    "password": "mahtab23"
}

邮递员回应:

{
    "key": "f75b9f54848a94ac04f455321118aff5d5a7e6f8"
}

0 个答案:

没有答案