Sends a redirect to the given (optionally relative) URL. If the ``status`` argument is specified, that value is used as the HTTP status code; otherwise either 301 (permanent) or 302 (temporary) is chosen based on the ``permanent`` argument. The default is 302 (tempor
(
self, url: str, permanent: bool = False, status: Optional[int] = None
)
| 796 | return get_signature_key_version(value) |
| 797 | |
| 798 | def redirect( |
| 799 | self, url: str, permanent: bool = False, status: Optional[int] = None |
| 800 | ) -> None: |
| 801 | """Sends a redirect to the given (optionally relative) URL. |
| 802 | |
| 803 | If the ``status`` argument is specified, that value is used as the |
| 804 | HTTP status code; otherwise either 301 (permanent) or 302 |
| 805 | (temporary) is chosen based on the ``permanent`` argument. |
| 806 | The default is 302 (temporary). |
| 807 | """ |
| 808 | if self._headers_written: |
| 809 | raise Exception("Cannot redirect after headers have been written") |
| 810 | if status is None: |
| 811 | status = 301 if permanent else 302 |
| 812 | else: |
| 813 | assert isinstance(status, int) and 300 <= status <= 399 |
| 814 | self.set_status(status) |
| 815 | self.set_header("Location", utf8(url)) |
| 816 | self.finish() |
| 817 | |
| 818 | def write(self, chunk: Union[str, bytes, dict]) -> None: |
| 819 | """Writes the given chunk to the output buffer. |