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

Already on GitHub? Sign in to your account

allow static routes to link to external urls #611

Closed
mmerickel opened this Issue May 24, 2012 · 7 comments

Comments

Projects
None yet
2 participants
Owner

mmerickel commented May 24, 2012

config.add_route('foo', 'http://example.com/bar.aspx', static=True)

@ghost ghost assigned tomster Aug 16, 2013

Member

tomster commented Aug 16, 2013

+1 and checked with @mcdonc who gave his blessing :)

Owner

mmerickel commented Aug 16, 2013

The 2 features that maybe aren't obvious are that the urls should accept placeholder patterns just like normal routes, and that there needs to be a protocol-agnostic way to define the url similar to add_static_view which uses the // prefix.

Member

tomster commented Aug 16, 2013

can you give examples for what you mean with 'should accept placeholder patterns'?

and i have to admit i have no idea what you mean with the second sentence...

my approach right now is to simply make route_url return the verbatim value configured instead of http://localhost:8080/http%3A//example.com/bar.aspx

Owner

mmerickel commented Aug 16, 2013

config.add_route('foo', 'http://example.com/{where}/{to}/index.html', static=True)
request.route_url('foo', where='hello', to='world')
# -> http://example.com/hello/world/index.html

This would also support the other features of a route like a pregenerator, *elements, query_ and anchor_.

A protocol-agnostic route would be one that depends on the current protocol. For example if the current request is https then we would generate links to https urls.

config.add_route('foo', '//example.com', static=True)
request.route_url('foo')
# -> https://example.com

The agnostic part of add_static_view is here: https://github.com/Pylons/pyramid/blob/master/pyramid/config/views.py#L1860

Most of this functionality is already covered by Pyramid's route generation semantics and should just fall into place, I just wanted to make sure it was explicitly mentioned. The only thing that would need to be fixed is the protocol-agnostic part.

Owner

mmerickel commented Aug 16, 2013

I guess route_path should either raise an error here, or probably preferably just return the full url, same as route_url would.

Member

tomster commented Aug 17, 2013

we discussed the route_path behavior and agreed that returning the path is acceptable.

Member

tomster commented Aug 17, 2013

closing this, any further discussion should take place at the pull request #1101

@tomster tomster closed this Aug 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment