websauna.system.core.views.redirect module¶
Defining redirects quickly.
-
websauna.system.core.views.redirect.
redirect_view
(path, new_path=None, new_route=None, status_code=302, name=None)[source]¶ Generate a redirect view.
Assign the return value of this function to a module level variable. configuration.scan() will pick it up and make a redirect route.
Give a new route name or direct path where requests should be redirected.
Example usage:
# Product no longer available _redirect = redirect_view("/old-page", new_route="home", status_code=301) _redirect2 = redirect_view("/old-page-2", new_route="home", status_code=301) # SEO optimized path _seo_redirect = redirect_view("/old-path-name", new_route="new_route_name", status_code=301)
TODO:
Add regex matching and such.
‘ Inefficient internal implementation
- Parameters
path (
str
) – Old path to be redirected to a new locationnew_route (
Optional
[str
]) – A named route where requests are redirected.new_path (
Optional
[str
]) – A URL path where requests are redirected.status_code (
int
) – 301 for permanent redirect, 302 for temporary directname (
Optional
[str
]) – Optional route name. If not set it is generated from path.