首页 > 解决方案 > 避免他人请求 URL 和修改用户数据 [DJANGO]

问题描述

在我的问题中,我提到了 django,但这是关于与后端的用户交互机制的一般问题。我正在开发 iOS 应用程序,例如,我想让用户更新电子邮件地址,因此我的后端是:

class UpdateEmail(APIView):
    serializer_class = EmailSerializer

    def put(self, request):
        user_id = request.data.get('id')
        new_email = request.data.get('new_email').lower()

        User.objects.filter(id=user_id).update(email=new_email)
        return Response('OK')

如您所见,我提出了这种类型的 put 请求:

{
   "id":user_id_logged_in_mobile_device_stored_locally,
   "email":new_email
}

我的问题是,如何避免其他人发出 PUT 请求并修改某些用户的信息?也许这不是解决问题的正确方法。

标签: djangorequest

解决方案


推荐阅读