##// END OF EJS Templates
Merge pull request #6861 from quantopian/template_dir_option...
Min RK -
r18722:65cef91b merge
parent child Browse files
Show More
@@ -0,0 +1,29 b''
1 * Added support for configurable user-supplied `Jinja
2 <http://jinja.pocoo.org/>`_ HTML templates for the notebook. Paths to
3 directories containing template files can be specified via
4 ``NotebookApp.extra_template_paths``. User-supplied template directories
5 searched first by the notebook, making it possible to replace existing
6 templates with your own files.
7
8 For example, to replace the notebook's built-in ``error.html`` with your own,
9 create a directory like ``/home/my_templates`` and put your override template
10 at ``/home/my_templates/error.html``. To start the notebook with your custom
11 error page enabled, you would run::
12
13 ipython notebook '--extra_template_paths=["/home/my_templates/"]'
14
15 It's also possible to override a template while also `inheriting
16 <http://jinja.pocoo.org/docs/dev/templates/#template-inheritance>`_ from that
17 template, by prepending ``templates/`` to the ``{% extends %}`` target of
18 your child template. This is useful when you only want to override a
19 specific block of a template. For example, to add additional CSS to the
20 built-in ``error.html``, you might create an override that looks like::
21
22 {% extends "templates/error.html" %}
23
24 {% block stylesheet %}
25 {{super()}}
26 <style type="text/css">
27 /* My Awesome CSS */
28 </style>
29 {% endblock %}
@@ -4,6 +4,22 b' import os'
4 # Packagers: modify this line if you store the notebook static files elsewhere
4 # Packagers: modify this line if you store the notebook static files elsewhere
5 DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
5 DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
6
6
7 # Packagers: modify the next line if you store the notebook template files
8 # elsewhere
9
10 # Include both IPython/html/ and IPython/html/templates/. This makes it
11 # possible for users to override a template with a file that inherits from that
12 # template.
13 #
14 # For example, if you want to override a specific block of notebook.html, you
15 # can create a file called notebook.html that inherits from
16 # templates/notebook.html, and the latter will resolve correctly to the base
17 # implementation.
18 DEFAULT_TEMPLATE_PATH_LIST = [
19 os.path.dirname(__file__),
20 os.path.join(os.path.dirname(__file__), "templates"),
21 ]
22
7 del os
23 del os
8
24
9 from .nbextensions import install_nbextension No newline at end of file
25 from .nbextensions import install_nbextension
@@ -51,7 +51,10 b' from tornado import httpserver'
51 from tornado import web
51 from tornado import web
52 from tornado.log import LogFormatter, app_log, access_log, gen_log
52 from tornado.log import LogFormatter, app_log, access_log, gen_log
53
53
54 from IPython.html import DEFAULT_STATIC_FILES_PATH
54 from IPython.html import (
55 DEFAULT_STATIC_FILES_PATH,
56 DEFAULT_TEMPLATE_PATH_LIST,
57 )
55 from .base.handlers import Template404
58 from .base.handlers import Template404
56 from .log import log_request
59 from .log import log_request
57 from .services.kernels.kernelmanager import MappingKernelManager
60 from .services.kernels.kernelmanager import MappingKernelManager
@@ -138,7 +141,10 b' class NotebookWebApplication(web.Application):'
138 log, base_url, default_url, settings_overrides,
141 log, base_url, default_url, settings_overrides,
139 jinja_env_options=None):
142 jinja_env_options=None):
140
143
141 _template_path = settings_overrides.get("template_path", os.path.join(os.path.dirname(__file__), "templates"))
144 _template_path = settings_overrides.get(
145 "template_path",
146 ipython_app.template_file_path,
147 )
142 if isinstance(_template_path, str):
148 if isinstance(_template_path, str):
143 _template_path = (_template_path,)
149 _template_path = (_template_path,)
144 template_path = [os.path.expanduser(path) for path in _template_path]
150 template_path = [os.path.expanduser(path) for path in _template_path]
@@ -519,7 +525,20 b' class NotebookApp(BaseIPythonApplication):'
519 def static_file_path(self):
525 def static_file_path(self):
520 """return extra paths + the default location"""
526 """return extra paths + the default location"""
521 return self.extra_static_paths + [DEFAULT_STATIC_FILES_PATH]
527 return self.extra_static_paths + [DEFAULT_STATIC_FILES_PATH]
522
528
529 extra_template_paths = List(Unicode, config=True,
530 help="""Extra paths to search for serving jinja templates.
531
532 Can be used to override templates from IPython.html.templates."""
533 )
534 def _extra_template_paths_default(self):
535 return []
536
537 @property
538 def template_file_path(self):
539 """return extra paths + the default locations"""
540 return self.extra_template_paths + DEFAULT_TEMPLATE_PATH_LIST
541
523 nbextensions_path = List(Unicode, config=True,
542 nbextensions_path = List(Unicode, config=True,
524 help="""paths for Javascript extensions. By default, this is just IPYTHONDIR/nbextensions"""
543 help="""paths for Javascript extensions. By default, this is just IPYTHONDIR/nbextensions"""
525 )
544 )
General Comments 0
You need to be logged in to leave comments. Login now