Create `/view` route, handler, and template

pull/1905/head
Grant Nestor 9 years ago
parent b7dcae6a56
commit 0034f2a251

@ -265,6 +265,7 @@ class NotebookWebApplication(web.Application):
handlers.extend([(r"/login", settings['login_handler_class'])])
handlers.extend([(r"/logout", settings['logout_handler_class'])])
handlers.extend(load_handlers('files.handlers'))
handlers.extend(load_handlers('view.handlers'))
handlers.extend(load_handlers('notebook.handlers'))
handlers.extend(load_handlers('nbconvert.handlers'))
handlers.extend(load_handlers('bundler.handlers'))

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>{{page_title}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<style type="text/css">
html, body, #container {
height: 100%;
}
body, #container {
overflow: hidden;
margin: 0;
}
#iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
<div id="container">
<iframe id="iframe" sandbox="allow-scripts" src="/files/{{file_path}}"></iframe>
</div>
</body>
</html>

@ -0,0 +1,26 @@
#encoding: utf-8
"""Tornado handlers for viewing HTML files."""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from tornado import web
from ..base.handlers import IPythonHandler, path_regex
from ..utils import url_escape
class ViewHandler(IPythonHandler):
"""Render HTML files within an iframe."""
@web.authenticated
def get(self, path):
path = path.strip('/')
if not self.contents_manager.file_exists(path):
raise web.HTTPError(404, u'File does not exist: %s' % path)
basename = path.rsplit('/', 1)[-1]
self.write(
self.render_template('view.html', file_path=url_escape(path), page_title=basename)
)
default_handlers = [
(r"/view%s" % path_regex, ViewHandler),
]
Loading…
Cancel
Save