錯誤信息python
AssertionError: Expected view UserListUpdate to be called with a URL keyword a rgument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
代碼函數
# views.py class UserUpdate(UpdateAPIView): """ 用戶更改密碼 """ queryset = User.objects.all() serializer_class = UserUpdateSerializer permission_classes = (IsAuthenticated,) # serializers.py class UserUpdateSerializer(serializers.ModelSerializer): class Meta: .... # 更新 def update(self, instance, validated_data): instance.username = validated_data.get('username') instance.set_password(validated_data.get('password')) instance.save() return validated_data
class UserUpdate(UpdateAPIView): """ 用戶更改密碼 """ queryset = User.objects.all() serializer_class = UserUpdateSerializer permission_classes = (IsAuthenticated,) # 獲取當前已經登陸用戶信息 傳入 def get_object(self): return self.request.user