Timing Django Requests

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from time import time

class TimerMiddleware:
    def process_request(self, request):
        request._tm_start_time = time()

    def process_response(self, request, response):
        if not hasattr(request, "_tm_start_time"):
            return

        total = time() - request._tm_start_time

        response['X-Django-Request-Time'] = '%fs' % total
        return response

More like this

  1. Ignore HTTP Accept-Language headers by fonso 6 years, 11 months ago
  2. Header view decorators by ydm 1 year, 2 months ago
  3. HTTP headers view decorator by dottedmag 6 years, 10 months ago
  4. Add Extra Headers to Test Client Requests by luftyluft 5 years, 9 months ago
  5. nginx x-accel-redirect protection of static files by sean 6 years, 4 months ago

Comments

(Forgotten your password?)