pyramid_redirect is a small extension for Pyramid to redirect urls before further processing takes place.
Just do
pip install pyramid_redirect
or
easy_install pyramid_redirect
pyramid_redirect runs with pyramid>=1.3 and python>=2.7 and python>=3.5. Other versions might also work.
Usage example:
def main(global_config, **settings): config = Configurator(settings=settings) config.include('pyramid_redirect') # add url redirecting rules... # first parameter is a regular expression # second parameter is the target url config.add_redirect_rule(r'http://example\.com/favicon.ico', r'http://example.com/static/favicon.ico') config.add_redirect_rule( r'http://example\.com/gallery/(?P<subpath>.*)', r'http://example.com/root/%(subpath)s', permanent=True, headers={'X-Value': 'foo'} ) # # ... rest of configuration # # return WSGI application instance return config.make_wsgi_app()
See tests for more examples.
If you use structlog, add the following configuration setting to your INI file to enable structlog-like logging:
pyramid_redirect.structlog = true
- Update CHANGES.rst.
- Update setup.py version.
- Run
bin/longtest
. - Run
bin/mkrelease -d pypi
.
At Niteo we regularly contribute back to the Open Source community. If you do too, we'd like to invite you to join our team!