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
- Form field with fixed value by roam 1 week, 5 days ago
- New Snippet! by Antoliny0919 2 weeks, 4 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 6 months, 4 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.