handlers.py 884 B

123456789101112131415161718192021222324252627
  1. #encoding: utf-8
  2. """Tornado handlers for viewing HTML files."""
  3. # Copyright (c) Jupyter Development Team.
  4. # Distributed under the terms of the Modified BSD License.
  5. from tornado import web
  6. from ..base.handlers import IPythonHandler, path_regex
  7. from ..utils import url_escape, url_path_join
  8. class ViewHandler(IPythonHandler):
  9. """Render HTML files within an iframe."""
  10. @web.authenticated
  11. def get(self, path):
  12. path = path.strip('/')
  13. if not self.contents_manager.file_exists(path):
  14. raise web.HTTPError(404, u'File does not exist: %s' % path)
  15. basename = path.rsplit('/', 1)[-1]
  16. file_url = url_path_join(self.base_url, 'files', url_escape(path))
  17. self.write(
  18. self.render_template('view.html', file_url=file_url, page_title=basename)
  19. )
  20. default_handlers = [
  21. (r"/view%s" % path_regex, ViewHandler),
  22. ]