Skip to content
Myr

Described HTTP methods

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

authored by Armin Ronacher · committed by Armin Ronacher · parent df929c6 · Browse files · 1 file+57 added−0 removed
This commit

State

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

Diff stats

1 file+57 added−0 removed

  • other:+57 added−0 removed

1 file+57 added−0 removed

modified:docs/quickstart.rst+57 added
159 unmodified lines
160explained below. It basically tells flask to think we are handling a161request even though we are not, we are in an interactive Python shell.162Have a look at the explanation below. :ref:`context-locals`).163164Why would you want to build URLs instead of hardcoding them in your165templates? There are three good reasons for this:1661671. reversing is often more descriptive than hardcoding the URLs. Also and168 more importantly you can change URLs in one go without having to change169 the URLs all over the place.1702. URL building will handle escaping of special characters and unicode171 data transparently for you, you don't have to deal with that.1723. If your application is placed outside the URL root (so say in173 ``/myapplication`` instead of ``/``), :func:`~flask.url_for` will174 handle that properly for you.175176177HTTP Methods178````````````179180HTTP knows different methods to access URLs. By default a route only
12 unmodified lines
193don't have to deal with that. It will also make sure that ``HEAD``194requests are handled like the RFC demands, so you can completely ignore195that part of the HTTP specification.196197You have no idea what an HTTP method is? Worry not, here quick198introduction in HTTP methods and why they matter:199200The HTTP method (also often called "the verb") tells the server what the201clients wants to *do* with the requested page. The following methods are202very common:203204`GET`205 The Browser tells the server: just *get* me the information stored on206 that page and send them to me. This is probably the most common207 method.208209`HEAD`210 The Browser tells the server: get me the information, but I am only211 interested in the *headers*, not the content of the page. An212 application is supposed to handle that as if a `GET` request was213 received but not deliver the actual contents. In Flask you don't have214 to deal with that at all, the underlying Werkzeug library handles that215 for you.216217`POST`218 The browser tells the server that it wants to *post* some new219 information to that URL and that the server must ensure the data is220 stored and only stored once.221222`PUT`223 Similar to `POST` but the server might trigger the store procedure224 multiple times by overwriting the old values more than once. Now you225 might be asking why this is any useful, but there are some good226 reasons to do that. Consider the connection is lost during227 transmission, in that situation a system between the browser and the228 server might sent the request safely a second time without breaking229 things. With `POST` that would not be possible because it might only230 be triggered once.231232`DELETE`233 Remove the information that the given location.234235Now the interesting part is that in HTML4 and XHTML1, the only methods a236form might submit to the server are `GET` and `POST`. But with JavaScript237and future HTML standards you can use other methods as well. Furthermore238HTTP became quite popular lately and there are more things than browsers239that are speaking HTTP. (Your revision control system for instance might240speak HTTP)241242Static Files243------------244245Dynamic web applications need static files as well. That's usually where
342 unmodified lines