Merge pull request #4847 from mhsmathew/patch-1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Grey Li · committed by GitHub · parents e7c82f9, 5dfd212 · Browse files · 1 file·+45 added−45 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+45 added−45 removed
- other:+45 added−45 removed
Provenance
- Commit
2a54cfa- Tree
fef68ea- Author
Grey Li <withlihui@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
e7c82f9- Parent 2
5dfd212
1 file changed+45 added−45 removed
modified:docs/api.rst+45 added-45 removed
1 unmodified line2 ===3 4 .. module:: flask5 6-This part of the documentation covers all the interfaces of Flask. For6+This part of the documentation covers all the interfaces of Flask. For7 parts where Flask depends on external libraries, we document the most8 important right here and provide links to the canonical documentation.9 10 22 unmodified lines33 34 .. attribute:: request35 36 To access incoming request data, you can use the global `request`37- object. Flask parses incoming request data for you and gives you38- access to it through that global object. Internally Flask makes37+ object. Flask parses incoming request data for you and gives you38+ access to it through that global object. Internally Flask makes39 sure that you always get the correct data for the active thread if you40 are in a multithreaded environment.41 42- This is a proxy. See :ref:`notes-on-proxies` for more information.42+ This is a proxy. See :ref:`notes-on-proxies` for more information.43 44 The request object is an instance of a :class:`~flask.Request`.45 46 21 unmodified lines68 69 The session object works pretty much like an ordinary dict, with the70 difference that it keeps track of modifications.71 72- This is a proxy. See :ref:`notes-on-proxies` for more information.72+ This is a proxy. See :ref:`notes-on-proxies` for more information.73 74 The following attributes are interesting:75 76 .. attribute:: new1 unmodified line78 ``True`` if the session is new, ``False`` otherwise.79 80 .. attribute:: modified81 82- ``True`` if the session object detected a modification. Be advised82+ ``True`` if the session object detected a modification. Be advised83 that modifications on mutable structures are not picked up84 automatically, in that situation you have to explicitly set the85- attribute to ``True`` yourself. Here an example::85+ attribute to ``True`` yourself. Here an example::86 87 # this change is not picked up because a mutable object (here88 # a list) is changed.89 session['objects'].append(42)2 unmodified lines92 93 .. attribute:: permanent94 95 If set to ``True`` the session lives for96- :attr:`~flask.Flask.permanent_session_lifetime` seconds. The97- default is 31 days. If set to ``False`` (which is the default) the96+ :attr:`~flask.Flask.permanent_session_lifetime` seconds. The97+ default is 31 days. If set to ``False`` (which is the default) the98 session will be deleted when the user closes the browser.99 100 101 Session Interface52 unmodified lines154 .. currentmodule:: flask155 156 To share data that is valid for one request only from one function to157 another, a global variable is not good enough because it would break in158-threaded environments. Flask provides you with a special object that158+threaded environments. Flask provides you with a special object that159 ensures it is only valid for the active request and that will return160-different values for each request. In a nutshell: it does the right160+different values for each request. In a nutshell: it does the right161 thing, like it does for :class:`request` and :class:`session`.162 163 .. data:: g164 181 unmodified lines346 .. versionadded:: 0.6347 348 .. data:: signals.signals_available349 350- ``True`` if the signaling system is available. This is the case350+ ``True`` if the signaling system is available. This is the case351 when `blinker`_ is installed.352 353 The following signals exist in Flask:354 355 .. data:: template_rendered356 357- This signal is sent when a template was successfully rendered. The357+ This signal is sent when a template was successfully rendered. The358 signal is invoked with the instance of the template as `template`359 and the context as dictionary (named `context`).360 361 Example subscriber::25 unmodified lines387 388 .. data:: request_started389 390 This signal is sent when the request context is set up, before391- any request processing happens. Because the request context is already391+ any request processing happens. Because the request context is already392 bound, the subscriber can access the request with the standard global393 proxies such as :class:`~flask.request`.394 395 Example subscriber::11 unmodified lines407 408 Example subscriber::409 410 def log_response(sender, response, **extra):411- sender.logger.debug('Request context is about to close down. '411+ sender.logger.debug('Request context is about to close down. '412 'Response: %s', response)413 414 from flask import request_finished415 request_finished.connect(log_response, app)28 unmodified lines444 got_request_exception.connect(log_security_exception, app)445 446 .. data:: request_tearing_down447 448- This signal is sent when the request is tearing down. This is always449- called, even if an exception is caused. Currently functions listening448+ This signal is sent when the request is tearing down. This is always449+ called, even if an exception is caused. Currently functions listening450 to this signal are called after the regular teardown handlers, but this451 is not something you can rely on.452 453 Example subscriber::9 unmodified lines463 there was one.464 465 .. data:: appcontext_tearing_down466 467- This signal is sent when the app context is tearing down. This is always468- called, even if an exception is caused. Currently functions listening467+ This signal is sent when the app context is tearing down. This is always468+ called, even if an exception is caused. Currently functions listening469 to this signal are called after the regular teardown handlers, but this470 is not something you can rely on.471 472 Example subscriber::8 unmodified lines481 to the exception that caused the teardown if there was one.482 483 .. data:: appcontext_pushed484 485- This signal is sent when an application context is pushed. The sender486- is the application. This is usually useful for unittests in order to487- temporarily hook in information. For instance it can be used to485+ This signal is sent when an application context is pushed. The sender486+ is the application. This is usually useful for unittests in order to487+ temporarily hook in information. For instance it can be used to488 set a resource early onto the `g` object.489 490 Example usage::491 18 unmodified lines510 .. versionadded:: 0.10511 512 .. data:: appcontext_popped513 514- This signal is sent when an application context is popped. The sender515- is the application. This usually falls in line with the514+ This signal is sent when an application context is popped. The sender515+ is the application. This usually falls in line with the516 :data:`appcontext_tearing_down` signal.517 518 .. versionadded:: 0.10519 520 521 .. data:: message_flashed522 523- This signal is sent when the application is flashing a message. The523+ This signal is sent when the application is flashing a message. The524 messages is sent as `message` keyword argument and the category as525 `category`.526 527 Example subscriber::9 unmodified lines537 538 .. class:: signals.Namespace539 540 An alias for :class:`blinker.base.Namespace` if blinker is available,541- otherwise a dummy class that creates fake signals. This class is541+ otherwise a dummy class that creates fake signals. This class is542 available for Flask extensions that want to provide the same fallback543 system as Flask itself.544 545 .. method:: signal(name, doc=None)32 unmodified lines578 3. You can directly access the underlying Werkzeug routing system579 which is exposed as :attr:`flask.Flask.url_map`.580 581 Variable parts in the route can be specified with angular brackets582-(``/user/<username>``). By default a variable part in the URL accepts any582+(``/user/<username>``). By default a variable part in the URL accepts any583 string without a slash however a different converter can be specified as584 well by using ``<converter:name>``.585 586 Variable parts are passed to the view function as keyword arguments.25 unmodified lines612 def show_post(post_id):613 pass614 615 An important detail to keep in mind is how Flask deals with trailing616-slashes. The idea is to keep each URL unique so the following rules616+slashes. The idea is to keep each URL unique so the following rules617 apply:618 619 1. If a rule ends with a slash and is requested without a slash by the620 user, the user is automatically redirected to the same page with a621 trailing slash attached.622 2. If a rule does not end with a trailing slash and the user requests the623 page with a trailing slash, a 404 not found is raised.624 625-This is consistent with how web servers deal with static files. This625+This is consistent with how web servers deal with static files. This626 also makes it possible to use relative link targets safely.627 628-You can also define multiple rules for the same function. They have to be629-unique however. Defaults can also be specified. Here for example is a628+You can also define multiple rules for the same function. They have to be629+unique however. Defaults can also be specified. Here for example is a630 definition for a URL that accepts an optional page::631 632 @app.route('/users/', defaults={'page': 1})633 @app.route('/users/page/<int:page>')14 unmodified lines648 def region(id):649 pass650 651 Here are the parameters that :meth:`~flask.Flask.route` and652-:meth:`~flask.Flask.add_url_rule` accept. The only difference is that652+:meth:`~flask.Flask.add_url_rule` accept. The only difference is that653 with the route parameter the view function is defined with the decorator654 instead of the `view_func` parameter.655 656 =============== ==========================================================657 `rule` the URL rule as string658-`endpoint` the endpoint for the registered URL rule. Flask itself658+`endpoint` the endpoint for the registered URL rule. Flask itself659 assumes that the name of the view function is the name660 of the endpoint if not explicitly stated.661 `view_func` the function to call when serving a request to the662- provided endpoint. If this is not provided one can662+ provided endpoint. If this is not provided one can663 specify the function later by storing it in the664 :attr:`~flask.Flask.view_functions` dictionary with the665 endpoint as key.666-`defaults` A dictionary with defaults for this rule. See the666+`defaults` A dictionary with defaults for this rule. See the667 example above for how defaults work.668 `subdomain` specifies the rule for the subdomain in case subdomain669- matching is in use. If not specified the default669+ matching is in use. If not specified the default670 subdomain is assumed.671 `**options` the options to be forwarded to the underlying672- :class:`~werkzeug.routing.Rule` object. A change to673- Werkzeug is handling of method options. methods is a list672+ :class:`~werkzeug.routing.Rule` object. A change to673+ Werkzeug is handling of method options. methods is a list674 of methods this rule should be limited to (``GET``, ``POST``675- etc.). By default a rule just listens for ``GET`` (and676- implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is675+ etc.). By default a rule just listens for ``GET`` (and676+ implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is677 implicitly added and handled by the standard request678- handling. They have to be specified as keyword arguments.678+ handling. They have to be specified as keyword arguments.679 =============== ==========================================================680 681 682 View Function Options3 unmodified lines686 customize behavior the view function would normally not have control over.687 The following attributes can be provided optionally to either override688 some defaults to :meth:`~flask.Flask.add_url_rule` or general behavior:689 690-- `__name__`: The name of a function is by default used as endpoint. If691- endpoint is provided explicitly this value is used. Additionally this690+- `__name__`: The name of a function is by default used as endpoint. If691+ endpoint is provided explicitly this value is used. Additionally this692 will be prefixed with the name of the blueprint by default which693 cannot be customized from the function itself.694 695 - `methods`: If methods are not provided when the URL rule is added,696 Flask will look on the view function object itself if a `methods`697- attribute exists. If it does, it will pull the information for the697+ attribute exists. If it does, it will pull the information for the698 methods from there.699 700 - `provide_automatic_options`: if this attribute is set Flask will701 either force enable or disable the automatic implementation of the702- HTTP ``OPTIONS`` response. This can be useful when working with702+ HTTP ``OPTIONS`` response. This can be useful when working with703 decorators that want to customize the ``OPTIONS`` response on a per-view704 basis.705 706 - `required_methods`: if this attribute is set, Flask will always add44 unmodified lines