我有一个 mixin,它定义了finalize_response()
要在另一个类中覆盖的方法:
class APILoggingMixin(object):
"""
Provides logging functionality by overriding finalize_response().
Intended to be mixed in with any rest_framework.views.APIView
"""
def finalize_response(self, request, response, *args, **kwargs):
logger.info('Some message.')
return super(APILoggingMixin, self).finalize_response(request, response, *args, **kwargs)
以及实现该finalize_response()
方法的类。在同一个模块中,logger
定义了全局变量:
import logging
logger = logging.getLogger(__name__)
class CategoryDetail(APILoggingMixin, generics.RetrieveUpdateDestroyAPIView):
"""
Retrieve, update or delete a Category.
"""
model = Category
serializer_class = CategorySerializer
permission_classes = (permissions.IsAuthenticated,)
如何访问logger
mixin 中的变量?