Using the same script but changing these two functions:
"""
def level1_include(config):
config.add_route('level1', '/')
#config.include(level2_include, route_prefix='/level2')
config.include(level2_include)
def level2_include(config):
#config.add_route('level2', '/')
config.add_route('level2', '/level2/')
"""
I want this to have the very same effect, because even though I
haven't included level2_include with a second prefix, it should still
carry over the "/level1" prefix because I'm calling it from within
level1_include. Instead it just creates the route "/level2/" at the
root.
My actual problem is concerning add_static_view:
"""
from pyramid.config import Configurator
from paste.httpserver import serve
def static_include(config):
config.add_static_view('static', 'path/to/static')
if __name__ == '__main__':
config = Configurator()
config.include(static_include, route_prefix='prefix')
serve(config.make_wsgi_app())
"""
However, this doesn't behave the same as my real code does. With this
script, "/prefix/static/filename" *does* work, but "/static/filename"
*also* matches. In my real code, *only* "/static/filename" matches.
I think I have narrowed it down to debug_toolbar. In this script, if
you change the configurator to:
config = Configurator(settings={'pyramid.includes':
'pyramid_debugtoolbar'})
For some reason, this causes "/prefix/static/filename" to stop
working.
And of course, in both cases, "/static/filename" should not match, but
it does.
On Sep 3, 4:57 pm, Chris McDonough <[email protected]> wrote:
> On Sat, 2011-09-03 at 12:20 -0700, jazg wrote:
> > If I have this:
>
> > config.include(include1, route_prefix="prefix")
> > def include1(config):
> > config.include(include2)
>
> > Any routes added within the "include2" function will *not* have the
> > prefix. It works if I pass route_prefix="/" to the second
> > config.include, but this doesn't help me if I'm using something other
> > than config.include. For example, I want to use add_static_view within
> > the include so that the static route will have the prefix added to it.
> > Is that possible?
>
> This script appears to produce the correct behavior:
>
> """
> from pyramid.view import view_config
> from pyramid.config import Configurator
> from pyramid.response import Response
> from paste.httpserver import serve
>
> @view_config(route_name='level0')
> def level0_view(request):
> return Response('Level 0')
>
> @view_config(route_name='level1')
> def level1_view(request):
> return Response('Level 1')
>
> @view_config(route_name='level2')
> def level2_view(request):
> return Response('Level 2')
>
> def level1_include(config):
> config.add_route('level1', '/')
> config.include(level2_include, route_prefix='/level2')
>
> def level2_include(config):
> config.add_route('level2', '/')
>
> if __name__ == '__main__':
> config = Configurator()
> config.add_route('level0', '/')
> config.include(level1_include, route_prefix='/level1')
> config.scan('__main__')
> serve(config.make_wsgi_app())
> """
>
> http://localhost:8080/-> "Level 0"http://localhost:8080/level1/-> "Level
> 1"http://localhost:8080/level1/level2/-> "Level 2"
>
> Can you provide a script like this that doesn't do what you want it to?
>
> - C
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.