Adds an 'X-Django-Request-Time' HTTP response header that times how long django spent processing the request.
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
- Serializer factory with Django Rest Framework by julio 3 months, 2 weeks ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 4 months ago
- Help text hyperlinks by sa2812 4 months, 4 weeks ago
- Stuff by NixonDash 7 months ago
- Add custom fields to the built-in Group model by jmoppel 9 months, 1 week ago
Comments
Please login first before commenting.