add redirect method to app

This commit is contained in:
Tim Hoagland 2022-05-02 12:44:15 -04:00 committed by David Lord
parent bd56d19b16
commit fdab801fbb
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
5 changed files with 55 additions and 1 deletions

View file

@ -22,6 +22,7 @@ from werkzeug.routing import MapAdapter
from werkzeug.routing import RequestRedirect
from werkzeug.routing import RoutingException
from werkzeug.routing import Rule
from werkzeug.utils import redirect as _wz_redirect
from werkzeug.wrappers import Response as BaseResponse
from . import cli
@ -1630,6 +1631,16 @@ class Flask(Scaffold):
return asgiref_async_to_sync(func)
def redirect(self, location: str, code: int = 302) -> BaseResponse:
"""Create a redirect response object.
:param location: the url of the redirect
:param code: http return code
.. versionadded:: 2.2
"""
return _wz_redirect(location, code=code, Response=self.response_class)
def make_response(self, rv: ResponseReturnValue) -> Response:
"""Convert the return value from a view function to an instance of
:attr:`response_class`.