@@ -233,26 +233,43 @@ def secure_filename(filename: str) -> str:
233233
234234
235235def redirect (
236- location : str , code : int = 302 , Response : type [Response ] | None = None
236+ location : str , code : int = 303 , Response : type [Response ] | None = None
237237) -> 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.
238+ """Create a response that redirects the client to the target location.
239+
240+ The default ``303 See Other`` status code instructs the client to make a
241+ ``GET`` request to the target, regardless of what method the current request
242+ is. This produces the correct result for the common use cases: page redirects
243+ and form success. The status codes you're likely to use are:
244+
245+ - ``303 See Other`` always uses a ``GET`` request.
246+ - ``307 Temporary Redirect`` preserves the current method.
247+ - ``308 Permanent Redirect`` preserves the current method, and instructs
248+ the client to permanently apply the result. This is hard to undo once
249+ you've sent it, so be sure the permanence is what you want.
250+
251+ Two older codes, ``302 Found`` and ``301 Moved Permanently``, are
252+ superseded by ``307`` and ``308`` respectively. They were not consistently
253+ implemented by clients, which tend to switch ``POST`` to ``GET`` but
254+ preserve other methods. Prefer using ``303``, ``307``, and ``308`` to get
255+ the exact behavior you intend. Other ``3xx`` codes are either not defined or
256+ have specific use cases.
257+
258+ :param location: The URL to redirect to. The client will interpret a
259+ relative URL (without the host) as relative to the host it's accessing.
260+ :param code: The redirect status code. This affects how the client issues
261+ the next request. Defaults to ``303``.
262+ :param Response: The response class. Defaults to
263+ :class:`werkzeug.wrappers.Response`.
264+
265+ .. versionchanged:: 3.2
266+ ``code`` defaults to 303 instead of 302.
267+
268+ .. versionchanged:: 0.10
269+ Added the ``response`` parameter.
270+
271+ .. versionchanged:: 0.6
272+ ``location`` can contain Unicode characters.
256273 """
257274 if Response is None :
258275 from .wrappers import Response
0 commit comments