update app.redirect docs

This commit is contained in:
David Lord 2022-05-12 16:30:01 -07:00
parent 5512a66881
commit fac630379d
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 17 additions and 11 deletions

View file

@ -5,13 +5,14 @@ Version 2.2.0
Unreleased Unreleased
- Add ``aborter_class`` and ``aborter`` attributes to the Flask app - Add new customization points to the ``Flask`` app object for many
object. ``flask.abort`` will call ``app.aborter``. This makes it previously global behaviors.
possible for an app to override how aborts work, including custom
status codes. :issue:`4567` - ``flask.abort`` will call ``app.aborter``.
- Add an ``app.redirect`` method, which ``flask.redirect`` will call. ``Flask.aborter_class`` and ``Flask.make_aborter`` can be used
This makes it possible for an app to override how redirects work. to customize this aborter. :issue:`4567`
:issue:`4569` - ``flask.redirect`` will call ``app.redirect``. :issue:`4569`
- Refactor ``register_error_handler`` to consolidate error checking. - Refactor ``register_error_handler`` to consolidate error checking.
Rewrite some error messages to be more consistent. :issue:`4559` Rewrite some error messages to be more consistent. :issue:`4559`

View file

@ -1664,8 +1664,11 @@ class Flask(Scaffold):
def redirect(self, location: str, code: int = 302) -> BaseResponse: def redirect(self, location: str, code: int = 302) -> BaseResponse:
"""Create a redirect response object. """Create a redirect response object.
:param location: the url of the redirect This is called by :func:`flask.redirect`, and can be called
:param code: http return code directly as well.
:param location: The URL to redirect to.
:param code: The status code for the redirect.
.. versionadded:: 2.2 .. versionadded:: 2.2
""" """

View file

@ -349,8 +349,8 @@ def redirect(
) -> "BaseResponse": ) -> "BaseResponse":
"""Create a redirect response object. """Create a redirect response object.
If :data:`~flask.current_app` is available, it will use If :data:`~flask.current_app` is available, it will use its
:meth:`~flask.app.Flask.redirect`, otherwise it will use :meth:`~flask.Flask.redirect` method, otherwise it will use
:func:`werkzeug.utils.redirect`. :func:`werkzeug.utils.redirect`.
:param location: The URL to redirect to. :param location: The URL to redirect to.
@ -359,6 +359,8 @@ def redirect(
``current_app`` is active, which uses ``app.response_class``. ``current_app`` is active, which uses ``app.response_class``.
.. versionadded:: 2.2 .. versionadded:: 2.2
Calls ``current_app.redirect`` if available instead of always
using Werkzeug's default ``redirect``.
""" """
if current_app: if current_app:
return current_app.redirect(location, code=code) return current_app.redirect(location, code=code)