从drf进行patch()调用

时间:2018-11-12 11:16:34

标签: django django-rest-framework

class UserProfile(viewsets.ModelViewSet):
    .......
    .......
    #some codes here
    .......

@csrf_exempt
def change_user_password(self, request):
    #some actions here 
    if(condition):
       UserProfile.patch(request)
    ..........
    return ...

在这里,我提供了示例代码,该代码可能无法运行。但是我需要做的只是从UserProfile函数对change_user_password视图集类进行补丁调用

1 个答案:

答案 0 :(得分:1)

亲密无间,您只需要创建UserProfile的对象,请参见示例代码的编辑内容:

class UserProfile(viewsets.ModelViewSet):
    .......
    .......
    #some codes here
    .......

def change_user_password(self, request):
    #some actions here 
    if(condition):
       user_profile_obj = UserProfile()
       user_profile_obj.patch(request)
    ..........
    return ...
相关问题