    def _get_next_url(self, owner, spawner):
        """Get next_url for a given owner/spawner"""
        next_url = self.get_argument("next", "")
        next_url = self._validate_next_url(next_url)
        if next_url:
            return next_url

        # default behavior:
        # if it's active, redirect to server URL
        if spawner.name in owner.spawners:
            spawner = owner.spawners[spawner.name]
            if spawner.active:
                # redirect to spawner url
                next_url = owner.server_url(spawner.name)

        if not next_url:
            # spawner not active
            # TODO: next_url not specified and not running, what do we do?
            # for now, redirect as if it's running,
            # but that's very likely to fail on "You can't launch this server"
            # is there a better experience for this?
            next_url = owner.server_url(spawner.name)
        # validate again, which strips away host to just absolute path
        return self._validate_next_url(next_url)
Get next_url for a given owner/spawner
jupyterhub/handlers/pages.py