middleware.py 514 B

12345678910111213141516
  1. from . import Stopwatch
  2. class StopwatchMiddleware(object):
  3. def process_request(self, request):
  4. request.stopwatch = Stopwatch()
  5. def process_response(self, request, response):
  6. try:
  7. time = request.stopwatch.time()
  8. import os
  9. stat_file = open(os.getcwd() + os.sep + 'stopwatch.txt', 'a')
  10. stat_file.write("%s s\n" % time)
  11. stat_file.close()
  12. except AttributeError:
  13. pass
  14. return response