This is how we are currently doing it:
from jupyterhub.handlers.base import BaseHandler
class AboutHandler(BaseHandler):
def initialize(self, profile_vars):
self.profile_vars = profile_vars
@web.authenticated
async def get(self):
html = await self.render_template(
"about.html",
juptyterhub_version=os.environ.get("JUPYTERHUB_IMAGE"),
jupyterdb_version=os.environ.get("JUPYTERHUB_DB_IMAGE"),
jupyterlab_versions=self.profile_vars,
)
await self.finish(html)
c.JupyterHub.extra_handlers.extend(
[(r"about", AboutHandler, dict(profile_vars=profile_vars))]
)
This code works fine, but since extra_handlers
were deprecated, how would I set these extra routes up as a new service? Are there any examples available how to set this up?
Would I use a Custom Class which inherites from Service like this?
from jupyterhub.services.service import Service
from smat_jupyterhub.views.handler import AboutHandler
class AboutService(Service):
def __init__(self, profile_vars=None, **kwargs):
super().__init__(**kwargs)
self.handlers = [(r"/about", AboutHandler, dict(profile_vars=profile_vars))]
c.JupyterHub.services = [
{
"name": "aboutservice",
"command": [sys.executable, "/usr/local/bin/aboutservice.py"],
"url": "http://127.0.0.1:8080",
},
It improved a bit, I see a new “Service” Link in my Navbar, however it is empty. I also tried just using the handler, but also results in an empty website.
This is my handler:
class AboutHandler(BaseHandler):
def initialize(self, profile_vars):
self.profile_vars = profile_vars
@web.authenticated
async def get(self):
html = await self.render_template(
"about.html",
juptyterhub_version=os.environ.get("JUPYTERHUB_IMAGE"),
jupyterdb_version=os.environ.get("JUPYTERHUB_DB_IMAGE"),
jupyterlab_versions=self.profile_vars,
)
await self.finish(html)