redirect defaults to 303 (#5898)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by GitHub · parents eb58d86, eca5fd1 · Browse files · 4 files·+14 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+14 added−3 removed
- other:+14 added−3 removed
Provenance
- Commit
809d5a8- Tree
2c77303- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
eb58d86- Parent 2
eca5fd1
4 files changed+14 added−3 removed
modified:docs/api.rst+1 added-1 removed
594 unmodified lines595 This specifies that ``/users/`` will be the URL for page one and596 ``/users/page/N`` will be the URL for page ``N``.597 598 If a URL contains a default value, it will be redirected to its simpler599-form with a 301 redirect. In the above example, ``/users/page/1`` will599+form with a 308 redirect. In the above example, ``/users/page/1`` will600 be redirected to ``/users/``. If your route handles ``GET`` and ``POST``601 requests, make sure the default route only handles ``GET``, as redirects602 can't preserve form data. ::603 105 unmodified linesmodified:src/flask/sansio/app.py+4 added-1 removed
930 unmodified lines931 .. versionadded:: 0.10932 """933 return False934 935- def redirect(self, location: str, code: int = 302) -> BaseResponse:935+ def redirect(self, location: str, code: int = 303) -> BaseResponse:936 """Create a redirect response object.937 938 This is called by :func:`flask.redirect`, and can be called939 directly as well.940 941 :param location: The URL to redirect to.942 :param code: The status code for the redirect.943 944+ .. versionchanged:: 3.2945+ ``code`` defaults to ``303`` instead of ``302``.946+947 .. versionadded:: 2.2948 Moved from ``flask.redirect``, which calls this method.949 """950 return _wz_redirect(59 unmodified linesmodified:src/flask/helpers.py+4 added-1 removed
237 unmodified lines238 )239 240 241 def redirect(242- location: str, code: int = 302, Response: type[BaseResponse] | None = None242+ location: str, code: int = 303, Response: type[BaseResponse] | None = None243 ) -> BaseResponse:244 """Create a redirect response object.245 246 If :data:`~flask.current_app` is available, it will use its4 unmodified lines251 :param code: The status code for the redirect.252 :param Response: The response class to use. Not used when253 ``current_app`` is active, which uses ``app.response_class``.254 255+ .. versionchanged:: 3.2256+ ``code`` defaults to ``303`` instead of ``302``.257+258 .. versionadded:: 2.2259 Calls ``current_app.redirect`` if available instead of always260 using Werkzeug's default ``redirect``.261 """377 unmodified linesmodified:CHANGES.rst+5 added
14 unmodified lines15 shows a deprecation warning, and will continue to work during the16 deprecation period. :issue:`5815`17 - ``template_filter``, ``template_test``, and ``template_global`` decorators18 can be used without parentheses. :issue:`5729`19+- ``redirect`` returns a ``303`` status code by default instead of ``302``.20+ This tells the client to always switch to ``GET``, rather than only21+ switching ``POST`` to ``GET``. This preserves the current behavior of22+ ``GET`` and ``POST`` redirects, and is also correct for frontend libraries23+ such as HTMX. :issue:`5895`24 25 26 Version 3.1.227 -------------1622 unmodified lines