    def patch_templates(self):
        """Patch page templates to add Hub-related buttons"""

        self.jinja_template_vars['logo_url'] = self.hub_host + url_path_join(
            self.hub_prefix, 'logo'
        )
        self.jinja_template_vars['hub_host'] = self.hub_host
        self.jinja_template_vars['hub_prefix'] = self.hub_prefix
        self.jinja_template_vars['hub_control_panel_url'] = (
            self.hub_host + url_path_join(self.hub_prefix, 'home')
        )

        settings = self.web_app.settings
        # patch classic notebook jinja env
        jinja_envs = []
        if 'jinja2_env' in settings:
            # default jinja env (should we do this on jupyter-server, or only notebook?)
            jinja_envs.append(settings['jinja2_env'])
        for ext_name in ("notebook", "nbclassic"):
            env_name = f"{ext_name}_jinja2_env"
            if env_name in settings:
                # when running with jupyter-server, classic notebook (nbclassic server extension or notebook v7)
                # gets its own jinja env, which needs the same patch
                jinja_envs.append(settings[env_name])

        # patch jinja env loading to get modified template, only for base page.html
        template_dir = Path(__file__).resolve().parent.joinpath("templates")
        with template_dir.joinpath("page.html").open() as f:
            page_template = f.read()

        def get_page(name):
            if name == 'page.html':
                return page_template

        for jinja_env in jinja_envs:
            jinja_env.loader = ChoiceLoader(
                [FunctionLoader(get_page), jinja_env.loader]
            )
Patch page templates to add Hub-related buttons
jupyterhub/singleuser/mixins.py