MCPcopy
hub / github.com/pallets/werkzeug / redirect

Function redirect

src/werkzeug/utils.py:235–272  ·  view source on GitHub ↗

Returns a response object (a WSGI application) that, if called, redirects the client to the target location. Supported codes are 301, 302, 303, 305, 307, and 308. 300 is not supported because it's not a real redirect and 304 because it's the answer for a request with a request with d

(
    location: str, code: int = 302, Response: type[Response] | None = None
)

Source from the content-addressed store, hash-verified

233
234
235def redirect(
236 location: str, code: int = 302, Response: type[Response] | None = None
237) -> Response:
238 """Returns a response object (a WSGI application) that, if called,
239 redirects the client to the target location. Supported codes are
240 301, 302, 303, 305, 307, and 308. 300 is not supported because
241 it's not a real redirect and 304 because it's the answer for a
242 request with a request with defined If-Modified-Since headers.
243
244 .. versionadded:: 0.6
245 The location can now be a unicode string that is encoded using
246 the :func:`iri_to_uri` function.
247
248 .. versionadded:: 0.10
249 The class used for the Response object can now be passed in.
250
251 :param location: the location the response should redirect to.
252 :param code: the redirect status code. defaults to 302.
253 :param class Response: a Response class to use when instantiating a
254 response. The default is :class:`werkzeug.wrappers.Response` if
255 unspecified.
256 """
257 if Response is None:
258 from .wrappers import Response
259
260 html_location = escape(location)
261 response = Response( # type: ignore[misc]
262 "<!doctype html>\n"
263 "<html lang=en>\n"
264 "<title>Redirecting...</title>\n"
265 "<h1>Redirecting...</h1>\n"
266 "<p>You should be redirected automatically to the target URL: "
267 f'<a href="{html_location}">{html_location}</a>. If not, click the link.\n',
268 code,
269 mimetype="text/html",
270 )
271 response.headers["Location"] = location
272 return response
273
274
275def append_slash_redirect(environ: WSGIEnvironment, code: int = 308) -> Response:

Callers 15

redirect_loop_appFunction · 0.90
redirect_with_get_appFunction · 0.90
local_redirect_appFunction · 0.90
appFunction · 0.90
appFunction · 0.90
processMethod · 0.90
newFunction · 0.90
linkFunction · 0.90
on_new_urlMethod · 0.90
on_follow_short_linkMethod · 0.90

Calls 1

ResponseClass · 0.50

Tested by 7

redirect_loop_appFunction · 0.72
redirect_with_get_appFunction · 0.72
local_redirect_appFunction · 0.72
appFunction · 0.72
appFunction · 0.72