5 messages in com.googlegroups.pylons-discussRe: mapping /static
FromSent OnAttachments
Max Ischenko11 Jun 2007 03:48 
voltron11 Jun 2007 03:58 
Max Ischenko26 Jun 2007 23:56 
voltron27 Jun 2007 00:41 
Max Ischenko28 Jun 2007 05:40 
Subject:Re: mapping /static
From:voltron (nhyt@public.gmane.org)
Date:06/27/2007 12:41:52 AM
List:com.googlegroups.pylons-discuss

Cool, would this also work behind a proxy server? The static path being on the proxy?

On Jun 27, 8:57 am, Max Ischenko
<isch@public.gmane.org> wrote:

On Jun 11, 1:48 pm, "Max Ischenko"
<isch@public.gmane.org> wrote:

Hello,

Default Pylons setup (middleware.py) configures StaticURLParser to handle APP/public/ which contains static dir. I wanted a slightly different setup and moved APP/public/static to static/ dir. Now I can't get it to work with StaticURLParser: it wants a serve everything under specific dir and in my case it means whole source tree.

How can I make sure Pylons serves static files from static/ dir under URL path /static?

Here is the solution I used; may be someone find it helpful too.

class MyStaticHandler(object): def __init__(self, static_dir): self.app = StaticURLParser(static_dir)

def __call__(self, environ, start_response): path_info = environ.get('PATH_INFO') or '' if path_info.startswith('/static/'): # trim /static/ prefix so that StaticURLParser # can actually locate the file environ['PATH_INFO'] = path_info[len('/static/'):] return self.app(environ, start_response) else: return self.app.not_found(environ, start_response)

This WSGI bit is used in place of normal static_app; all it does is modify PATH_INFO so that StaticURLParser can work correctly.

Max.