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

support mounting routes without a trailing slash #3415

Closed
wants to merge 4 commits into from

Conversation

mmerickel
Copy link
Member

@mmerickel mmerickel commented Nov 4, 2018

This PR replaces #1639. Closes #406.

The gist is this snippet that was added to the docs.

from pyramid.config import Configurator

def users_include(config):
    config.add_route('show_users', '')

def main(global_config, **settings):
    config = Configurator()
    config.include(users_include, route_prefix='/users')

The above configuration will match ``/users`` instead of ``/users/`` if a slash
had been supplied to the :meth:`pyramid.config.Configurator.add_route` function.

This is backward-incompatible for anyone mounting routes and using an empty string.

Alternative approaches that could maintain compatibility:

  1. Support a sentinel value as the pattern. For example:
from pyramid.config import NO_APPEND_SLASH

def users_include(config):
    config.add_route('show_users', NO_APPEND_SLASH)

This is somewhat cumbersome.

  1. Add an option to add_route that a user could opt into.
def users_include(config):
    config.add_route('show_users', '', route_prefix_append_slash=False)

I'm open to something like this and am curious what people think. Pyramid has a somewhat ingrained history of supporting '' == '/' and this makes them different, but only in a specific use case. When used from main or without a route_prefix, they are still equivalent and result in a trailing slash. I'm not convinced it's worth the incompatibility.

ping @nek4life

@stevepiercy
Copy link
Member

Are you talking about only prefix-based routes, only routes without prefixes, or both?

I define routes with leading and trailing slashes to avoid any guesswork, so I don't have an opinion about this feature.

@mmerickel
Copy link
Member Author

closing in favor of #3420

@mmerickel mmerickel closed this Nov 12, 2018
@mmerickel mmerickel deleted the bare-route-prefix branch November 29, 2020 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

route_prefix doesn't allow the prefix pattern to match without a trailing slash
3 participants