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
Provenance
- Commit
3fa4fd0- Tree
8efb721- Author
defuz <defuz.net@gmail.com>- Committer
defuz <defuz.net@gmail.com>- Parent
8284217
11 files changed+44 added−44 removed
modified:docs/patterns/jquery.rst+1 added-1 removed
154 unmodified lines155 3. ``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).159-4. ``$.getJSON(url, data, func)`` sends a `GET` request to `url` and will159+4. ``$.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 linesmodified:docs/patterns/wtforms.rst+2 added-2 removed
59 unmodified lines60 61 Things to remember:62 63 1. 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``.66 2. to validate the data, call the :func:`~wtforms.form.Form.validate`67 method which will return ``True`` if the data validates, ``False``68 otherwise.69 3. to access individual values from the form, access `form.<NAME>.data`.57 unmodified linesmodified:docs/tutorial/templates.rst+1 added-1 removed
56 unmodified lines57 58 This template extends the `layout.html` template from above to display the59 messages. Note that the `for` loop iterates over the messages we passed60 in with the :func:`~flask.render_template` function. We also tell the61-form to submit to your `add_entry` function and use `POST` as HTTP61+form to submit to your `add_entry` function and use ``POST`` as HTTP62 method:63 64 .. sourcecode:: html+jinja65 46 unmodified linesmodified:docs/tutorial/views.rst+1 added-1 removed
27 unmodified lines28 Add New Entry29 -------------30 31 This view lets the user add new entries if they are logged in. This only32-responds to `POST` requests, the actual form is shown on the32+responds 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 and35 redirect back to the `show_entries` page::36 62 unmodified linesmodified:docs/api.rst+8 added-8 removed
31 unmodified lines32 :members:33 34 .. attribute:: form35 36- 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.39 40 .. attribute:: args41 28 unmodified lines70 71 .. attribute:: files72 73 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 lines703 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 lines732 methods from there.733 734 - `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.739 740 - `required_methods`: if this attribute is set, Flask will always add741 these methods when registering a URL rule even if the methods were48 unmodified linesmodified:docs/quickstart.rst+15 added-15 removed
290 unmodified lines291 HTTP Methods292 ````````````293 294 HTTP (the protocol web applications are speaking) knows different methods for295-accessing URLs. By default, a route only answers to `GET` requests, but that295+accessing URLs. By default, a route only answers to ``GET`` requests, but that296 can be changed by providing the `methods` argument to the297 :meth:`~flask.Flask.route` decorator. Here are some examples::298 299 from flask import request4 unmodified lines304 do_the_login()305 else:306 show_the_login_form()307 308-If `GET` is present, `HEAD` will be added automatically for you. You309-don't have to deal with that. It will also make sure that `HEAD` requests308+If ``GET`` is present, ``HEAD`` will be added automatically for you. You309+don't have to deal with that. It will also make sure that ``HEAD`` requests310 are handled as the `HTTP RFC`_ (the document describing the HTTP311 protocol) demands, so you can completely ignore that part of the HTTP312-specification. Likewise, as of Flask 0.6, `OPTIONS` is implemented for you312+specification. Likewise, as of Flask 0.6, ``OPTIONS`` is implemented for you313 automatically as well.314 315 You have no idea what an HTTP method is? Worry not, here is a quick316 introduction to HTTP methods and why they matter:1 unmodified line318 The HTTP method (also often called "the verb") tells the server what the319 clients wants to *do* with the requested page. The following methods are320 very common:321 322-`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.325 326-`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.333 334-`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.339 340-`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.349 350-`DELETE`350+``DELETE``351 Remove the information at the given location.352 353-`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.357 358 Now the interesting part is that in HTML4 and XHTML1, the only methods a359-form can submit to the server are `GET` and `POST`. But with JavaScript359+form can submit to the server are ``GET`` and ``POST``. But with JavaScript360 and future HTML standards you can use the other methods as well. Furthermore361 HTTP has become quite popular lately and browsers are no longer the only362 clients that are using HTTP. For instance, many revision control systems363 use it.176 unmodified lines540 from flask import request541 542 The current request method is available by using the543 :attr:`~flask.request.method` attribute. To access form data (data544-transmitted in a `POST` or `PUT` request) you can use the544+transmitted in a ``POST`` or ``PUT`` request) you can use the545 :attr:`~flask.request.form` attribute. Here is a full example of the two546 attributes mentioned above::547 548 @app.route('/login', methods=['POST', 'GET'])345 unmodified linesmodified:docs/security.rst+2 added-2 removed
68 unmodified lines69 don't keep that in mind, some people might be able to trick your70 application's users with social engineering to do stupid things without71 them knowing.72 73-Say you have a specific URL that, when you sent `POST` requests to will73+Say you have a specific URL that, when you sent ``POST`` requests to will74 delete a user's profile (say `http://example.com/user/delete`). If an75 attacker now creates a page that sends a post request to that page with76 some JavaScript they just has to trick some users to load that page and77 their profiles will end up being deleted.51 unmodified lines129 "email": "admin@localhost"}130 ]131 132 And it is doing that of course only as long as you are logged in and only133-for you. And it is doing that for all `GET` requests to a certain URL,133+for you. And it is doing that for all ``GET`` requests to a certain URL,134 say the URL for that request is135 ``http://example.com/api/get_friends.json``.136 137 So now what happens if a clever hacker is embedding this to his website38 unmodified linesmodified:docs/testing.rst+1 added-1 removed
110 unmodified lines111 112 Notice that our test functions begin with the word `test`; this allows113 :mod:`unittest` to automatically identify the method as a test to run.114 115-By using `self.app.get` we can send an HTTP `GET` request to the application with115+By using `self.app.get` we can send an HTTP ``GET`` request to the application with116 the given path. The return value will be a :class:`~flask.Flask.response_class` object.117 We can now use the :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect118 the 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 linesmodified:docs/views.rst+1 added-1 removed
44 unmodified lines45 :meth:`~flask.views.View.as_view` class method. The string you pass to46 that function is the name of the endpoint that view will then have. But47 this by itself is not helpful, so let's refactor the code a bit::48 49- 49+50 from flask.views import View51 52 class ListView(View):53 184 unmodified linesmodified:flask/app.py+10 added-10 removed
966 unmodified lines967 .. versionchanged:: 0.2968 `view_func` parameter added.969 970 .. versionchanged:: 0.6971- `OPTIONS` is added automatically as method.971+ ``OPTIONS`` is added automatically as method.972 973 :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 as3 unmodified lines979 :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 line991 methods = options.pop('methods', None)992 993 # 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 lines1047 :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 lines1558 func()1559 self._got_first_request = True1560 1561 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.1565 1566 .. versionadded:: 0.71567 """1568 adapter = _request_ctx_stack.top.url_adapter341 unmodified linesmodified:CHANGES+2 added-2 removed
324 unmodified lines325 Released on June 28th 2011, codename Grappa326 327 - 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 lines378 -------------379 380 Bugfix release, released on December 31st 2010381 382-- 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