forked from jupyterlab/jupyterlab
/
main.py
53 lines (39 loc) · 1.59 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
An example demonstrating a stand-alone "filebrowser".
Copyright (c) Jupyter Development Team.
Distributed under the terms of the Modified BSD License.
Example
-------
To run the example, see the instructions in the README to build it. Then
run ``python main.py``.
"""
import os
from jinja2 import FileSystemLoader
from notebook.base.handlers import IPythonHandler, FileFindHandler
from notebook.notebookapp import NotebookApp
from traitlets import Unicode
HERE = os.path.dirname(__file__)
class ExampleHandler(IPythonHandler):
"""Handle requests between the main app page and notebook server."""
def get(self):
"""Get the main page for the application's interface."""
return self.write(self.render_template('index.html',
static=self.static_url,
base_url=self.base_url,
token=self.settings['token']))
def get_template(self, name):
loader = FileSystemLoader(HERE)
return loader.load(self.settings['jinja2_env'], name)
class ExampleApp(NotebookApp):
default_url = Unicode('/example')
def init_webapp(self):
"""initialize tornado webapp and httpserver.
"""
super(ExampleApp, self).init_webapp()
default_handlers = [
(r'/example/?', ExampleHandler),
(r"/example/(.*)", FileFindHandler,
{'path': os.path.join(HERE, 'build')}) ]
self.web_app.add_handlers('.*$', default_handlers)
if __name__ == '__main__':
ExampleApp.launch_instance()