Issues with url's server proxy

Hello, I have set up JupyterHub in a Kubernetes cluster, running alongside a Django application.

In my Kubernetes configuration, I’ve defined a custom configuration file ( to manage server proxies. Specifically, I’ve configured a server named ‘viewer’ with certain settings, including a base URL of ‘’.

    mountPath: /usr/local/etc/jupyter/
    stringData: |
      c = get_config()
      c.ServerProxy.servers = {
          'viewer': {
              'command': [
              'port': 7777,
              'absolute_url': False,

In my Django application’s settings, I’ve configured FORCE_SCRIPT_NAME to be ‘/viewer’. However, when I navigate through the app by clicking buttons, the URLs are incorrect. For example, I’m getting instead of the expected<user>/viewer/projectadd.

How can I ensure that the URLs generated are correct and include the intended base URL (<user>/)?

I’m not sure how django configures these things, but if you have hardcoded /viewer where you should probably have /user/:username/viewer. You can use {base_url} as an argument in command to your command, to get the prefix needed that should be prepended to your URL handlers.

Thank you, minrk! I’ve found a solution by storing the username in an environment variable and then retrieving it within the Django settings.

To achieve the desired configuration, you can save the username as an environment variable and then retrieve it within Django settings as follows:


CURRENT_USERNAME: “{username}”

import os

Retrieve the username from environment variables or default to ‘admin’ if not found

username = os.getenv(‘CURRENT_USERNAME’, ‘admin’)

Define static URL and script name based on the retrieved username

STATIC_URL = f’/hub/user/{username}/style/’
FORCE_SCRIPT_NAME = f’/hub/user/{username}/viewer’

This setup ensures dynamic handling of the username within your Django settings, allowing flexibility and customization based on the environment.

The whole prefix (/user/{username}/) is available as $JUPYTERHUB_SERVICE_PREFIX, if you want to use that (it should not start with /hub/, unless that’s set as your JupyterHub.base_url, in which case the main hub page would be /hub/hub/).