Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:13+00:00 2026-05-31T18:46:13+00:00

In Pyramid , add_notfound_view(append_slash=True) will cause a request which does not match any view,

  • 0

In Pyramid, add_notfound_view(append_slash=True) will cause a request which does not match any view, but which would match a view if a trailing slash existed on the end, to be redirected to the matching view.

Does an inverse to this exist? That is: If I have a route configured as

config.add_route('list_reports', '/reports')

and a user requests /reports/, is there a simple way to cause them to be redirected appropriately?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:46:14+00:00Added an answer on May 31, 2026 at 6:46 pm

    The non-global solution

    Add a second route for each view that you want redirected.

    config = Configurator()
    def add_auto_route(name, pattern, **kw):
        config.add_route(name, pattern, **kw)
        if not pattern.endswith('/'):
            config.add_route(name + '-auto', pattern + '/')
            def redirector(request):
                return HTTPMovedPermanently(request.route_url(name))
            config.add_view(redirector, route_name=name + '-auto')
    
    add_auto_route('list_reports', '/reports')
    

    Globally redirect all routes (never support slash-appended routes)

    Simply rewrite the URLs. This can be done via pyramid_rewrite, or externally by your web server.

    config = Configurator()
    config.include('pyramid_rewrite')
    config.add_rewrite_rule(r'/(?P<path>.*)/', r'/%(path)s')
    

    Attempt to redirect if a route is not found

    Rip the AppendSlashNotFoundFactory out of pyramid’s source and invert it. Sorry, not doing that one for you here, but just as easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since Pyramid does not have any form dependencies, I need recommendations for form handling.
I have a Pyramid application which uses request.environ['REMOTE_ADDR'] in some places. The application is
I have a custom 404 view defined in my Pyramid app: @view_config(context=HTTPNotFound, renderer='404.pt') def
I am trying to use pyramid beaker in Pyramid framework and its just not
I'm using Pyramid framework and I want to access the IP address from which
I'm trying to generate a request token using oauth2 in a Pyramid application for
I'm using Pyramid and SQLAlchemy, but the following simplified code: u = u\u201C m
Is there any way to get pyramid absolute application url in main() function? I
I'd like to know how to edit pyramid registry at runtime. Well i'm not
I have a pyramid which has 5 vertex and 18 indices. As I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.