From a2536e1bdb2e42656325a57d727da4b666e6390d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Dunstr=C3=B6m?= Date: Fri, 27 Apr 2018 11:40:12 +0200 Subject: [PATCH 1/2] Added short note about Werkzeug redirect behaviour --- docs/api.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 982c07ba..7b03a41a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -719,6 +719,8 @@ definition for a URL that accepts an optional page:: This specifies that ``/users/`` will be the URL for page one and ``/users/page/N`` will be the URL for page `N`. +Note: Underlying behaviour in Werkzeug redirect URLs containing a default value to its simpler form with a 301 redirect. + Here are the parameters that :meth:`~flask.Flask.route` and :meth:`~flask.Flask.add_url_rule` accept. The only difference is that with the route parameter the view function is defined with the decorator From 5d00869aa57ed50f4f10953efbc0f2b3a5fd3905 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 27 Apr 2018 09:53:29 -0700 Subject: [PATCH 2/2] expand explantion about default redirects --- docs/api.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 7b03a41a..cdb05638 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -717,9 +717,18 @@ definition for a URL that accepts an optional page:: pass This specifies that ``/users/`` will be the URL for page one and -``/users/page/N`` will be the URL for page `N`. - -Note: Underlying behaviour in Werkzeug redirect URLs containing a default value to its simpler form with a 301 redirect. +``/users/page/N`` will be the URL for page ``N``. + +If a URL contains a default value, it will be redirected to its simpler +form with a 301 redirect. In the above example, ``/users/page/1`` will +be redirected to ``/users/``. If your route handles ``GET`` and ``POST`` +requests, make sure the default route only handles ``GET``, as redirects +can't preserve form data. :: + + @app.route('/region/', defaults={'id': 1}) + @app.route('/region/', methods=['GET', 'POST']) + def region(id): + pass Here are the parameters that :meth:`~flask.Flask.route` and :meth:`~flask.Flask.add_url_rule` accept. The only difference is that