TW2 doesn't account for SCRIPT_NAME when generating resource links

Issue #77 resolved
Simon King
created an issue

TW2 doesn't seem to look at the wsgi SCRIPT_NAME parameter when generating links to CSS. This means that if you mount a WSGI app at a non-root URL, those links stop working.

I see that the TW2 middleware has a script_name configuration parameter, but this means that the middleware has to be configured differently when the application is mounted in a different place. The rest of my TurboGears2 application has needed no extra configuration when changing the mount point (as long as I'm careful to use tg.url to create URLs).

I don't know what the right way to fix this is - presumably always prepending SCRIPT_NAME has the potential to break things for people who aren't expecting it. Perhaps there could be a use_wsgi_script_name boolean config parameter?



Comments (3)

  1. Simon King reporter

    As a workaround, I've put this in my for my app:

    def monkeypatch_tw2():
        # TW2 doesn't use the wsgi SCRIPT_NAME variable
        # See
        import tw2.core.middleware
        import pylons
        class PatchedConfig(tw2.core.middleware.Config):
            def script_name(self):
                return pylons.request.environ.get('SCRIPT_NAME', '')
        tw2.core.middleware.Config = PatchedConfig
    def make_app(global_conf, full_stack=True, **app_conf):
        app = make_base_app(global_conf, full_stack=full_stack, **app_conf)
        return app
  2. Log in to comment