【问题标题】:Send Data to a Django UpdateAPIView through Axios通过 Axios 向 Django UpdateAPIView 发送数据
【发布时间】:2021-02-21 10:24:05
【问题描述】:

我在Axios patch request 的正文中发送Email

const userData = await this.$axios.patch(`/user/${id}/update/`, {
          email: value
        })

我正在使用 Django rest 框架将它发送到这个 API 视图

class UserAPIView(generics.UpdateAPIView):

    serializer_class = serializers.UserDetailsSerializer

    def get_object(self):
        return User.objects.filter(id='id')

我尝试在 Swagger 和 Postman 上运行它,它运行良好,但在 Axios 中,它会抛出一个错误

TypeError: Cannot read property 'email' of undefined

有没有其他的发送方式?谢谢!

【问题讨论】:

    标签: django vue.js django-rest-framework django-views axios


    【解决方案1】:

    在 js 代码中,你的 email 值未定义,请尝试硬编码 email 的一些值并检查它是否有效?

    const userData = await this.$axios.patch(`/user/${id}/update/`, {
              email: "hardcode@email.com" 
            })
    

    如果它有效,那么你应该检查你的 js 代码为什么它没有设置 email 的值。

    【讨论】:

      猜你喜欢
      • 2020-11-23
      • 2020-05-12
      • 2018-07-13
      • 2019-04-08
      • 2017-04-20
      • 2020-06-18
      • 2018-09-13
      • 2022-01-18
      • 2017-02-24
      相关资源
      最近更新 更多