class StatsMiddleware(object):
    duration = 0

def process_request(self, request):
    request.start_time = time.time()

def process_response(self, request, response):
    pass
Django Middleware — как редактировать HTML объекта Django Response?