I don’t think you will get better. The best way to register a request is by checking in your authentication class and adding an audit log to the request.
You can then use APIView to register the rendering time, against the AuditLog generated in the authentication class.
Here's an example of using Token authentication if each request has an Authorization: Bearer <Token> header.
settings.py
... REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'common.authentication.MyTokenAuthenticationClass' ), ..., }
generic /authentication.py
from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from ipware.ip import get_real_ip from rest_framework import authentication from rest_framework import exceptions from accounts.models import Token, AuditLog class MyTokenAuthenticationClass(authentication.BaseAuthentication): def authenticate(self, request):
You now have access to AuditLog in your request. Thus, you can register everything before and after verification.
source share