Guest User

stream logfile from django

a guest
Jun 16th, 2016
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def stream_file(request, b64fname):
  2.     def follow(fname):
  3.         fd = open(fname, 'r')
  4.         while True:
  5.             line = fd.readline()
  6.             if not line:
  7.                 continue
  8.             yield line + "<br/>"
  9.             yield " " * 1024  # Encourage browser to render incrementally
  10.  
  11.     fname = base64.urlsafe_b64decode(b64fname).decode('utf-8')
  12.     response = StreamingHttpResponse(
  13.         follow(fname),
  14.         content_type='text/html'
  15.     )
  16.     return response
RAW Paste Data