Merge remote-tracking branch 'origin/2.1.x'

This commit is contained in:
David Lord 2022-07-01 13:32:50 -07:00
commit 96d39c87a8
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
5 changed files with 275 additions and 279 deletions

View file

@ -313,6 +313,24 @@ of the :meth:`~flask.Flask.route` decorator to handle different HTTP methods.
else:
return show_the_login_form()
The example above keeps all methods for the route within one function,
which can be useful if each part uses some common data.
You can also separate views for different methods into different
functions. Flask provides a shortcut for decorating such routes with
:meth:`~flask.Flask.get`, :meth:`~flask.Flask.post`, etc. for each
common HTTP method.
.. code-block:: python
@app.get('/login')
def login_get():
return show_the_login_form()
@app.post('/login')
def login_post():
return do_the_login()
If ``GET`` is present, Flask automatically adds support for the ``HEAD`` method
and handles ``HEAD`` requests according to the `HTTP RFC`_. Likewise,
``OPTIONS`` is automatically implemented for you.