Returns a `status` redirect to the new URL. `url` is joined with the base URL so that things like `redirect("about") will work properly.
(self, url, status="301 Moved Permanently", absolute=False)
| 116 | """A `301 Moved Permanently` redirect.""" |
| 117 | |
| 118 | def __init__(self, url, status="301 Moved Permanently", absolute=False): |
| 119 | """ |
| 120 | Returns a `status` redirect to the new URL. |
| 121 | `url` is joined with the base URL so that things like |
| 122 | `redirect("about") will work properly. |
| 123 | """ |
| 124 | newloc = urljoin(ctx.path, url) |
| 125 | |
| 126 | if newloc.startswith("/"): |
| 127 | if absolute: |
| 128 | home = ctx.realhome |
| 129 | else: |
| 130 | home = ctx.home |
| 131 | newloc = home + newloc |
| 132 | |
| 133 | headers = {"Content-Type": "text/html", "Location": newloc} |
| 134 | HTTPError.__init__(self, status, headers, "") |
| 135 | |
| 136 | |
| 137 | redirect = Redirect |