Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyramid.config.Configurator.include() ignores route_prefix argument #628

Closed
avanov opened this issue Jul 1, 2012 · 7 comments
Closed

pyramid.config.Configurator.include() ignores route_prefix argument #628

avanov opened this issue Jul 1, 2012 · 7 comments
Labels

Comments

@avanov
Copy link
Contributor

avanov commented Jul 1, 2012

Suppose I want to make a route to a user's profile page. Current implementation of route_prefix is very limited:

  • it doesn't allow me to bind my profile page at /. (dot separates profile pages from other "system" pages).
    For example

       def included(config):
           config.add_route('show_user', '{userlogin}')
    
       def main(global_config, **settings):
           config = Configurator()
           config.include(included, route_prefix='/.')

    will be generating URLs like /{userlogin} (without preceding dot).

  • it adds unnecessary slash after a dash prefix. For example

       def included(config):
           config.add_route('show_user', '{userlogin}')
    
       def main(global_config, **settings):
           config = Configurator()
           config.include(included, route_prefix='/-')

    will be generating URLs like /-/{userlogin} which is incorrect prefix.

On the other hand, If I specify explicit prefixes to all of my add_route() calls

   def included(config):
       config.add_route('show_user', '/.{userlogin}')

the system generates URLs that I expect to see. Therefore the current behaviour of route_prefix should be treated as a bug.

Note, that the Pylons' equvalent code based on Routes' submapper copes with these cases.

@sontek
Copy link
Member

sontek commented Sep 23, 2012

Could you provide an example of this not working?

This code here works just fine:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)

def includeme(config):
    config.add_route('hello', '/hello/{name}')
    config.add_view(hello_world, route_name='hello')

if __name__ == '__main__':
    config = Configurator()
    config.include(includeme, route_prefix='/.foo')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    print 'http://0.0.0.0:8080'
    server.serve_forever()

@sontek
Copy link
Member

sontek commented Sep 23, 2012

Oh, I think I see what you want, which is:

route_prefix='/.'

which comes up with:

/.sontek/ for instance.

Thats not going to work, route_prefix appends a '/' at the end of the prefix.

so the route would be /./sontek

@sontek
Copy link
Member

sontek commented Sep 23, 2012

See #406

@avanov
Copy link
Contributor Author

avanov commented Sep 23, 2012

@sontek exactly. But, there's no a standard which would require us to use a forward slash each time we'd like to display some sort of hierarchy in URL. Prefixes are not supposed to be treated as a "filesystem-like root tree path". They should be just "prefixes" - i.e. char sequences that are prepended to the route paths.

@mcdonc
Copy link
Member

mcdonc commented Sep 23, 2012

You may wish it to not be true, but paths are what they are. That's unlikely to change in any "minor" release of Pyramid (any 1.X version). We might revisit it for a major version bump.

@avanov
Copy link
Contributor Author

avanov commented Sep 23, 2012

@mcdonc ok, I'm down with it. I just wanted to point out, that Web standards operate with concepts of "resources" and "resource urls", not paths. The whole story of "paths" is based on ability of web servers to transparently map a resource url right onto host's filesystem object. But it's a feature, not a standard. Therefore, IMO, it would be wise to have two different features in further pyramid releases: a route-prefix-as-path-prefix feature, and a route-prefix-as-just-a-prefix feature.

@mcdonc
Copy link
Member

mcdonc commented Sep 23, 2012

OK, well this issue is linked from #406 now, and it's got more details, so I'm going to close this one for now. We may revisit how route prefixing works in a new major release.

@mcdonc mcdonc closed this as completed Sep 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants