On Wed, Jan 5, 2011 at 10:23 AM, Dominik <d.roettsc...@gmail.com> wrote: > Hi Chris, > >> We have a "cookbook" in the works that describes how to do something >> like this. Here's a sneak peek: >> >> http://plope.com/static/pyramid_cookbook/static.html#root-relative-cu... > > Yes, thanks - I found something similar in the "Serving Static Assets" > documentation [1]. However, if I understood correctly, this still > wouldn't help for the standard case of responding to request to "/" > with the static "index.html", like apache does for example for > index.htm(l)/php/cgi etc. Any ideas? > > The whole static stuff seems very hacky for me, examples: > 1) from the same page: [1] "The special name *subpath above is used by > the pyramid.view.static view callable to signify the path of the file > relative to the directory you’re serving." > 2) The special purpose of the "name" attribute of the static view. > 3) The double meaning of add_static_view depending on the first > parameter (i.e. in the external host case) > > I wish this would be cleaned up some day, more consistent and more > intuitive to understand.
I'm testing an application template that serves static files from "/" and has a SQLAlchemy configuration (coming soon). This is working for me: from pyramid.view import static # Set up routes and views config.add_handler('home', '/', '{{package}}.handlers:MainHandler', action='index') config.add_handler('main', '/{action}', '{{package}}.handlers:MainHandler', path_info=r'/(?!favicon\.ico|robots\.txt|w3c)') config.add_route('static', '/*subpath', static('{{package}}:static')) The first line is a regular home route for "/". The second line handles "/{action}", but it has to exclude top-level static files which would be mistaken for actions. (The path_info regex doesn't match /favicon.ico, /robots.txt, or /w3c.) The third line is a catchall route for all other URLs, which goes to the static directory. The static() function creates a static view. But Chris has said this will disable traversal, so I need to make a route predicate function so that the route matches only if the file exists. But if you don't need traversal, you can use this as-is. -- Mike Orr <sluggos...@gmail.com> -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-de...@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.