Issue
I have my django GenericAPIView with post method, I want some part of the logic which uses self to be in some other method and exccute that code when my post method gets hit
class MyAPIView(GenericAPIView):
def post(self, request, *args, **kwargs):
Solution
You can do something like this!
class MyAPIView(CreateAPIView):
def custom_function(self):
"""place your logic here!"""
pass
def post(self, request, *args, **kwargs):
# This will call our custom function as soon as post request is hit
self.custom_function()
return super().post(request, *kwargs, *args)
Answered By - Shiva Bahadur Basnet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.