This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: html.base.handlers

Base Tornado handlers for the notebook server.

9 Classes

class IPython.html.base.handlers.AuthenticatedHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

A RequestHandler with an authenticated user.


The default Content-Security-Policy header

Can be overridden by defining Content-Security-Policy in settings[‘headers’]


Is a user currently logged in?


May a user proceed to log in?

This returns True if login capability is available, irrespective of whether the user is already logged in or not.


Return the login handler for this application, if any.

class IPython.html.base.handlers.IPythonHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.AuthenticatedHandler

IPython-specific extensions to authenticated handling

Mostly property shortcuts to IPython-specific settings.


Whether to set Access-Control-Allow-Credentials


Normal Access-Control-Allow-Origin


Regular expression version of allow_origin


Return the body of the request as JSON data.


Return the jinja template object for a given name


User-supplied values to supply to jinja templates.


use the IPython log by default, falling back on tornado’s logger


Add CORS headers, if defined


The version hash to use for cache hints for static files

write_error(status_code, **kwargs)

render custom error pages

class IPython.html.base.handlers.APIHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.IPythonHandler

Base class for API handlers


Check Origin for cross-site API requests.

Copied from WebSocket with changes:

  • allow unspecified host/origin (e.g. scripts)
class IPython.html.base.handlers.Template404(application, request, **kwargs)

Bases: IPython.html.base.handlers.IPythonHandler

Render our 404 template

class IPython.html.base.handlers.AuthenticatedFileHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.IPythonHandler, tornado.web.StaticFileHandler

static files should only be accessible when logged in

validate_absolute_path(root, absolute_path)

Validate and return the absolute path.

Requires tornado 3.1

Adding to tornado’s own handling, forbids the serving of hidden files.

class IPython.html.base.handlers.FileFindHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.IPythonHandler, tornado.web.StaticFileHandler

subclass of StaticFileHandler for serving files from a search path

classmethod get_absolute_path(roots, path)

locate a file to serve on our static file search path

validate_absolute_path(root, absolute_path)

check if the file should be served (raises 404, 403, etc.)

class IPython.html.base.handlers.APIVersionHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.APIHandler

class IPython.html.base.handlers.TrailingSlashHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

Simple redirect handler that strips trailing slashes

This should be the first, highest priority handler.

class IPython.html.base.handlers.FilesRedirectHandler(application, request, **kwargs)

Bases: IPython.html.base.handlers.IPythonHandler

Handler for redirecting relative URLs to the /files/ handler

static redirect_to_files(path)

make redirect logic a reusable static method

so it can be called from other handlers.

1 Function


Decorate methods with this to return GitHub style JSON errors.

This should be used on any JSON API on any handler method that can raise HTTPErrors.

This will grab the latest HTTPError exception using sys.exc_info and then:

  1. Set the HTTP status code based on the HTTPError
  2. Create and return a JSON body with a message field describing the error in a human readable form.