[英]Move some code from GenericAPIView post method to other methods in django
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我有我的 django GenericAPIView 和 post 方法,我想要一些使用 self 的逻辑在其他方法中,并在我的 post 方法被命中时执行该代码
class MyAPIView(GenericAPIView):
def post(self, request, *args, **kwargs):
You can do something like this!你可以做这样的事情!
class MyAPIView(CreateAPIView): class MyAPIView(创建APIView):
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.