请求正文未从axios get调用传递到Django Rest框架

请求正文未从axios get调用传递到Django Rest框架,django,reactjs,django-rest-framework,axios,postman,Django,Reactjs,Django Rest Framework,Axios,Postman,我在axios中发送带有主体的get请求时遇到问题。它不会将请求主体传递到后端 Axios代码如下所示 const FunctionName = (environment, page_num) => { axios.get(API_URL, { params: { environment, page_num },

我在axios中发送带有主体的get请求时遇到问题。它不会将请求主体传递到后端

Axios代码如下所示

const FunctionName = (environment, page_num) => {

    axios.get(API_URL, 
            { params: 
              {
                 environment,
                 page_num
              },

            }).then(res => {
                console.log(res);
            }).catch(err => {
                console.log(err.response.data);
            });
}
class TestView(APIView);
    def get(self, request):
       environment = request.data['environment']
       page_num = request.data['page_num'] 
       ...
       ...

我使用Django作为我的后端,我接收到空的body,即{},这会导致发送到后端的错误请求。我问了几个堆栈溢出问题,但没有一个对我有帮助。谁能帮我一下吗

更新

我的django代码如下所示

const FunctionName = (environment, page_num) => {

    axios.get(API_URL, 
            { params: 
              {
                 environment,
                 page_num
              },

            }).then(res => {
                console.log(res);
            }).catch(err => {
                console.log(err.response.data);
            });
}
class TestView(APIView);
    def get(self, request):
       environment = request.data['environment']
       page_num = request.data['page_num'] 
       ...
       ...

在这里,当我无法获取环境或页面数据时。同样的请求,当我从邮递员那里发送get调用和正文请求中的内容时,它接受并发回响应

重新更新


我注意到我们必须使用request.query_-params['some_-val']以防我们在Axios的请求中传递身体,但是request.query_-params['some_-val']将不起作用,如果我们在postman中发送身体请求。我不确定这是不是正常的行为

我不确定,但试试这个:

axios({
  method: "get",
  url: API_URL,
  body: {
    environment,
    page_num
  }
}).then(res => console.log(res.data)); 

在Django中,您是否尝试使用
请求获取body。body

我不确定,但请尝试以下操作:

axios({
  method: "get",
  url: API_URL,
  body: {
    environment,
    page_num
  }
}).then(res => console.log(res.data)); 

在Django,您是否尝试通过
请求获取body。body

任何面临此问题的人都可以在下面的链接中找到答案

可能的重复

任何面临此问题的人都可以在下面的链接中找到答案

可能重复

尝试axios.post,axios.get请求可能有一些limitations@Ajay在我的django APIView类中,还有另一个用于创建数据的post方法,如果使用post方法,则可能会发生冲突。Try axios.post可能重复,axios.get请求可能有一些limitations@Ajay在我的django APIView类中,有另一个用于创建数据的post方法,如果我使用post方法,则可能会发生冲突。可能的No重复仍然存在相同的问题。当您在请求正文中指定数据时,我们必须使用params对象指定。正如Axios文档中提到的,您是否尝试使用
request.body
获取body Django?我在Django中使用request.data['page_num']。因为我使用的是Django Rest框架,所以要获取请求的正文,我们需要使用request.data。不,仍然存在相同的问题。当您在请求主体中指定数据时,我们必须使用params对象指定。正如Axios文档中提到的,您是否尝试使用
request.body
获取body Django?我在Django中使用request.data['page_num']。因为我使用的是Django Rest框架,所以要获取请求的正文,我们需要使用request.data。