Skip to content
Myr

docs: http method names like ``GET`` and ``POST``

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by defuz · committed by defuz · parent 8284217 · Browse files · 11 files+44 added−44 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+44 added−44 removed

  • other:+44 added−44 removed

11 files+44 added−44 removed

modified:docs/patterns/jquery.rst+1 added-1 removed
154 unmodified lines
1553. ``element.bind('event', func)`` specifies a function that should run156 when the user clicked on the element. If that function returns157 `false`, the default behavior will not kick in (in this case, navigate158 to the `#` URL).1594. ``$.getJSON(url, data, func)`` sends a `GET` request to `url` and will1594. ``$.getJSON(url, data, func)`` sends a ``GET`` request to `url` and will160 send the contents of the `data` object as query parameters. Once the161 data arrived, it will call the given function with the return value as162 argument. Note that we can use the `$SCRIPT_ROOT` variable here that163 we set earlier.
5 unmodified lines
modified:docs/patterns/wtforms.rst+2 added-2 removed
59 unmodified lines
6061Things to remember:62631. create the form from the request :attr:`~flask.request.form` value if64 the data is submitted via the HTTP `POST` method and65 :attr:`~flask.request.args` if the data is submitted as `GET`.64 the data is submitted via the HTTP ``POST`` method and65 :attr:`~flask.request.args` if the data is submitted as ``GET``.662. to validate the data, call the :func:`~wtforms.form.Form.validate`67 method which will return ``True`` if the data validates, ``False``68 otherwise.693. to access individual values from the form, access `form.<NAME>.data`.
57 unmodified lines
modified:docs/tutorial/templates.rst+1 added-1 removed
56 unmodified lines
5758This template extends the `layout.html` template from above to display the59messages. Note that the `for` loop iterates over the messages we passed60in with the :func:`~flask.render_template` function. We also tell the61form to submit to your `add_entry` function and use `POST` as HTTP61form to submit to your `add_entry` function and use ``POST`` as HTTP62method:6364.. sourcecode:: html+jinja65
46 unmodified lines
modified:docs/tutorial/views.rst+1 added-1 removed
27 unmodified lines
28Add New Entry29-------------3031This view lets the user add new entries if they are logged in. This only32responds to `POST` requests, the actual form is shown on the32responds to ``POST`` requests, the actual form is shown on the33`show_entries` page. If everything worked out well we will34:func:`~flask.flash` an information message to the next request and35redirect back to the `show_entries` page::36
62 unmodified lines
modified:docs/api.rst+8 added-8 removed
31 unmodified lines
32 :members:3334 .. attribute:: form3536 A :class:`~werkzeug.datastructures.MultiDict` with the parsed form data from `POST`37 or `PUT` requests. Please keep in mind that file uploads will not36 A :class:`~werkzeug.datastructures.MultiDict` with the parsed form data from ``POST``37 or ``PUT`` requests. Please keep in mind that file uploads will not38 end up here, but instead in the :attr:`files` attribute.3940 .. attribute:: args41
28 unmodified lines
7071 .. attribute:: files7273 A :class:`~werkzeug.datastructures.MultiDict` with files uploaded as part of a74 `POST` or `PUT` request. Each file is stored as74 ``POST`` or ``PUT`` request. Each file is stored as75 :class:`~werkzeug.datastructures.FileStorage` object. It basically behaves like a76 standard file object you know from Python, with the difference that77 it also has a :meth:`~werkzeug.datastructures.FileStorage.save` function that can78 store the file on the filesystem.
624 unmodified lines
703 subdomain is assumed.704`**options` the options to be forwarded to the underlying705 :class:`~werkzeug.routing.Rule` object. A change to706 Werkzeug is handling of method options. methods is a list707 of methods this rule should be limited to (`GET`, `POST`708 etc.). By default a rule just listens for `GET` (and709 implicitly `HEAD`). Starting with Flask 0.6, `OPTIONS` is707 of methods this rule should be limited to (``GET``, ``POST``708 etc.). By default a rule just listens for ``GET`` (and709 implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is710 implicitly added and handled by the standard request711 handling. They have to be specified as keyword arguments.712=============== ==========================================================713
18 unmodified lines
732 methods from there.733734- `provide_automatic_options`: if this attribute is set Flask will735 either force enable or disable the automatic implementation of the736 HTTP `OPTIONS` response. This can be useful when working with737 decorators that want to customize the `OPTIONS` response on a per-view736 HTTP ``OPTIONS`` response. This can be useful when working with737 decorators that want to customize the ``OPTIONS`` response on a per-view738 basis.739740- `required_methods`: if this attribute is set, Flask will always add741 these methods when registering a URL rule even if the methods were
48 unmodified lines
modified:docs/quickstart.rst+15 added-15 removed
290 unmodified lines
291HTTP Methods292````````````293294HTTP (the protocol web applications are speaking) knows different methods for295accessing URLs. By default, a route only answers to `GET` requests, but that295accessing URLs. By default, a route only answers to ``GET`` requests, but that296can be changed by providing the `methods` argument to the297:meth:`~flask.Flask.route` decorator. Here are some examples::298299 from flask import request
4 unmodified lines
304 do_the_login()305 else:306 show_the_login_form()307308If `GET` is present, `HEAD` will be added automatically for you. You309don't have to deal with that. It will also make sure that `HEAD` requests308If ``GET`` is present, ``HEAD`` will be added automatically for you. You309don't have to deal with that. It will also make sure that ``HEAD`` requests310are handled as the `HTTP RFC`_ (the document describing the HTTP311protocol) demands, so you can completely ignore that part of the HTTP312specification. Likewise, as of Flask 0.6, `OPTIONS` is implemented for you312specification. Likewise, as of Flask 0.6, ``OPTIONS`` is implemented for you313automatically as well.314315You have no idea what an HTTP method is? Worry not, here is a quick316introduction to HTTP methods and why they matter:
1 unmodified line
318The HTTP method (also often called "the verb") tells the server what the319clients wants to *do* with the requested page. The following methods are320very common:321322`GET`322``GET``323 The browser tells the server to just *get* the information stored on324 that page and send it. This is probably the most common method.325326`HEAD`326``HEAD``327 The browser tells the server to get the information, but it is only328 interested in the *headers*, not the content of the page. An329 application is supposed to handle that as if a `GET` request was329 application is supposed to handle that as if a ``GET`` request was330 received but to not deliver the actual content. In Flask you don't331 have to deal with that at all, the underlying Werkzeug library handles332 that for you.333334`POST`334``POST``335 The browser tells the server that it wants to *post* some new336 information to that URL and that the server must ensure the data is337 stored and only stored once. This is how HTML forms usually338 transmit data to the server.339340`PUT`341 Similar to `POST` but the server might trigger the store procedure340``PUT``341 Similar to ``POST`` but the server might trigger the store procedure342 multiple times by overwriting the old values more than once. Now you343 might be asking why this is useful, but there are some good reasons344 to do it this way. Consider that the connection is lost during345 transmission: in this situation a system between the browser and the346 server might receive the request safely a second time without breaking347 things. With `POST` that would not be possible because it must only347 things. With ``POST`` that would not be possible because it must only348 be triggered once.349350`DELETE`350``DELETE``351 Remove the information at the given location.352353`OPTIONS`353``OPTIONS``354 Provides a quick way for a client to figure out which methods are355 supported by this URL. Starting with Flask 0.6, this is implemented356 for you automatically.357358Now the interesting part is that in HTML4 and XHTML1, the only methods a359form can submit to the server are `GET` and `POST`. But with JavaScript359form can submit to the server are ``GET`` and ``POST``. But with JavaScript360and future HTML standards you can use the other methods as well. Furthermore361HTTP has become quite popular lately and browsers are no longer the only362clients that are using HTTP. For instance, many revision control systems363use it.
176 unmodified lines
540 from flask import request541542The current request method is available by using the543:attr:`~flask.request.method` attribute. To access form data (data544transmitted in a `POST` or `PUT` request) you can use the544transmitted in a ``POST`` or ``PUT`` request) you can use the545:attr:`~flask.request.form` attribute. Here is a full example of the two546attributes mentioned above::547548 @app.route('/login', methods=['POST', 'GET'])
345 unmodified lines
modified:docs/security.rst+2 added-2 removed
68 unmodified lines
69don't keep that in mind, some people might be able to trick your70application's users with social engineering to do stupid things without71them knowing.7273Say you have a specific URL that, when you sent `POST` requests to will73Say you have a specific URL that, when you sent ``POST`` requests to will74delete a user's profile (say `http://example.com/user/delete`). If an75attacker now creates a page that sends a post request to that page with76some JavaScript they just has to trick some users to load that page and77their profiles will end up being deleted.
51 unmodified lines
129 "email": "admin@localhost"}130 ]131132And it is doing that of course only as long as you are logged in and only133for you. And it is doing that for all `GET` requests to a certain URL,133for you. And it is doing that for all ``GET`` requests to a certain URL,134say the URL for that request is135``http://example.com/api/get_friends.json``.136137So now what happens if a clever hacker is embedding this to his website
38 unmodified lines
modified:docs/testing.rst+1 added-1 removed
110 unmodified lines
111112Notice that our test functions begin with the word `test`; this allows113:mod:`unittest` to automatically identify the method as a test to run.114115By using `self.app.get` we can send an HTTP `GET` request to the application with115By using `self.app.get` we can send an HTTP ``GET`` request to the application with116the given path. The return value will be a :class:`~flask.Flask.response_class` object.117We can now use the :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect118the return value (as string) from the application. In this case, we ensure that119``'No entries here so far'`` is part of the output.
234 unmodified lines
modified:docs/views.rst+1 added-1 removed
44 unmodified lines
45:meth:`~flask.views.View.as_view` class method. The string you pass to46that function is the name of the endpoint that view will then have. But47this by itself is not helpful, so let's refactor the code a bit::4849 4950 from flask.views import View5152 class ListView(View):53
184 unmodified lines
modified:flask/app.py+10 added-10 removed
966 unmodified lines
967 .. versionchanged:: 0.2968 `view_func` parameter added.969970 .. versionchanged:: 0.6971 `OPTIONS` is added automatically as method.971 ``OPTIONS`` is added automatically as method.972973 :param rule: the URL rule as string974 :param endpoint: the endpoint for the registered URL rule. Flask975 itself assumes the name of the view function as
3 unmodified lines
979 :param options: the options to be forwarded to the underlying980 :class:`~werkzeug.routing.Rule` object. A change981 to Werkzeug is handling of method options. methods982 is a list of methods this rule should be limited983 to (`GET`, `POST` etc.). By default a rule984 just listens for `GET` (and implicitly `HEAD`).985 Starting with Flask 0.6, `OPTIONS` is implicitly983 to (``GET``, ``POST`` etc.). By default a rule984 just listens for ``GET`` (and implicitly ``HEAD``).985 Starting with Flask 0.6, ``OPTIONS`` is implicitly986 added and handled by the standard request handling.987 """988 if endpoint is None:989 endpoint = _endpoint_from_view_func(view_func)
1 unmodified line
991 methods = options.pop('methods', None)992993 # if the methods are not given and the view_func object knows its994 # methods we can use that instead. If neither exists, we go with995 # a tuple of only `GET` as default.995 # a tuple of only ``GET`` as default.996 if methods is None:997 methods = getattr(view_func, 'methods', None) or ('GET',)998 if isinstance(methods, string_types):999 raise TypeError('Allowed methods have to be iterables of strings, '
47 unmodified lines
1047 :param options: the options to be forwarded to the underlying1048 :class:`~werkzeug.routing.Rule` object. A change1049 to Werkzeug is handling of method options. methods1050 is a list of methods this rule should be limited1051 to (`GET`, `POST` etc.). By default a rule1052 just listens for `GET` (and implicitly `HEAD`).1053 Starting with Flask 0.6, `OPTIONS` is implicitly1051 to (``GET``, ``POST`` etc.). By default a rule1052 just listens for ``GET`` (and implicitly ``HEAD``).1053 Starting with Flask 0.6, ``OPTIONS`` is implicitly1054 added and handled by the standard request handling.1055 """1056 def decorator(f):1057 endpoint = options.pop('endpoint', None)
500 unmodified lines
1558 func()1559 self._got_first_request = True15601561 def make_default_options_response(self):1562 """This method is called to create the default `OPTIONS` response.1562 """This method is called to create the default ``OPTIONS`` response.1563 This can be changed through subclassing to change the default1564 behavior of `OPTIONS` responses.1564 behavior of ``OPTIONS`` responses.15651566 .. versionadded:: 0.71567 """1568 adapter = _request_ctx_stack.top.url_adapter
341 unmodified lines
modified:CHANGES+2 added-2 removed
324 unmodified lines
325Released on June 28th 2011, codename Grappa326327- Added :meth:`~flask.Flask.make_default_options_response`328 which can be used by subclasses to alter the default329 behavior for `OPTIONS` responses.329 behavior for ``OPTIONS`` responses.330- Unbound locals now raise a proper :exc:`RuntimeError` instead331 of an :exc:`AttributeError`.332- Mimetype guessing and etag support based on file objects is now333 deprecated for :func:`flask.send_file` because it was unreliable.
44 unmodified lines
378-------------379380Bugfix release, released on December 31st 2010381382- Fixed an issue where the default `OPTIONS` response was382- Fixed an issue where the default ``OPTIONS`` response was383 not exposing all valid methods in the `Allow` header.384- Jinja2 template loading syntax now allows "./" in front of385 a template load path. Previously this caused issues with386 module setups.
152 unmodified lines