Skip to content
Myr

api.rst

This file

Path

docs/api.rst

743 lines · 22.3 KiB

Last changed by

Changed interface for `flask.g`Armin Ronacherbefore adoptionc889fbc

History of this file

Take it

The walk stopped after 200 commits: lines older than 1a9e082 point at it.

tweaks to styleOri Livnehbefore adoption1a9e082

lines 1–217why, one step back
1.. _api:
23API4===56.. module:: flask78This part of the documentation covers all the interfaces of Flask. For9parts where Flask depends on external libraries, we document the most10important right here and provide links to the canonical documentation.111213Application Object14------------------1516.. autoclass:: Flask17 :members:18 :inherited-members:192021Blueprint Objects22-----------------2324.. autoclass:: Blueprint25 :members:26 :inherited-members:2728Incoming Request Data29---------------------3031.. autoclass:: Request32 :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 not38 end up here, but instead in the :attr:`files` attribute.3940 .. attribute:: args4142 A :class:`~werkzeug.datastructures.MultiDict` with the parsed contents of the query43 string. (The part in the URL after the question mark).4445 .. attribute:: values4647 A :class:`~werkzeug.datastructures.CombinedMultiDict` with the contents of both48 :attr:`form` and :attr:`args`.4950 .. attribute:: cookies5152 A :class:`dict` with the contents of all cookies transmitted with53 the request.5455 .. attribute:: stream5657 If the incoming form data was not encoded with a known mimetype58 the data is stored unmodified in this stream for consumption. Most59 of the time it is a better idea to use :attr:`data` which will give60 you that data as a string. The stream only returns the data once.6162 .. attribute:: headers6364 The incoming request headers as a dictionary like object.6566 .. attribute:: data6768 Contains the incoming request data as string in case it came with69 a mimetype Flask does not handle.7071 .. attribute:: files7273 A :class:`~werkzeug.datastructures.MultiDict` with files uploaded as part of a74 `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.7980 .. attribute:: environ8182 The underlying WSGI environment.8384 .. attribute:: method8586 The current request method (``POST``, ``GET`` etc.)8788 .. attribute:: path89 .. attribute:: script_root90 .. attribute:: url91 .. attribute:: base_url92 .. attribute:: url_root9394 Provides different ways to look at the current URL. Imagine your95 application is listening on the following URL::9697 http://www.example.com/myapplication9899 And a user requests the following URL::100101 http://www.example.com/myapplication/page.html?x=y102103 In this case the values of the above mentioned attributes would be104 the following:105106 ============= ======================================================107 `path` ``/page.html``108 `script_root` ``/myapplication``109 `base_url` ``http://www.example.com/myapplication/page.html``110 `url` ``http://www.example.com/myapplication/page.html?x=y``111 `url_root` ``http://www.example.com/myapplication/``112 ============= ======================================================113114 .. attribute:: is_xhr115116 `True` if the request was triggered via a JavaScript117 `XMLHttpRequest`. This only works with libraries that support the118 ``X-Requested-With`` header and set it to `XMLHttpRequest`.119 Libraries that do that are prototype, jQuery and Mochikit and120 probably some more.121122.. class:: request123124 To access incoming request data, you can use the global `request`125 object. Flask parses incoming request data for you and gives you126 access to it through that global object. Internally Flask makes127 sure that you always get the correct data for the active thread if you128 are in a multithreaded environment.129130 This is a proxy. See :ref:`notes-on-proxies` for more information.131132 The request object is an instance of a :class:`~werkzeug.wrappers.Request`133 subclass and provides all of the attributes Werkzeug defines. This134 just shows a quick overview of the most important ones.135136137Response Objects138----------------139140.. autoclass:: flask.Response141 :members: set_cookie, data, mimetype142143 .. attribute:: headers144145 A :class:`Headers` object representing the response headers.146147 .. attribute:: status148149 A string with a response status.150151 .. attribute:: status_code152153 The response status as integer.154155156Sessions157--------158159If you have the :attr:`Flask.secret_key` set you can use sessions in Flask160applications. A session basically makes it possible to remember161information from one request to another. The way Flask does this is by162using a signed cookie. So the user can look at the session contents, but163not modify it unless they know the secret key, so make sure to set that164to something complex and unguessable.165166To access the current session you can use the :class:`session` object:167168.. class:: session169170 The session object works pretty much like an ordinary dict, with the171 difference that it keeps track on modifications.172173 This is a proxy. See :ref:`notes-on-proxies` for more information.174175 The following attributes are interesting:176177 .. attribute:: new178179 `True` if the session is new, `False` otherwise.180181 .. attribute:: modified182183 `True` if the session object detected a modification. Be advised184 that modifications on mutable structures are not picked up185 automatically, in that situation you have to explicitly set the186 attribute to `True` yourself. Here an example::187188 # this change is not picked up because a mutable object (here189 # a list) is changed.190 session['objects'].append(42)191 # so mark it as modified yourself192 session.modified = True193194 .. attribute:: permanent195196 If set to `True` the session lives for197 :attr:`~flask.Flask.permanent_session_lifetime` seconds. The198 default is 31 days. If set to `False` (which is the default) the199 session will be deleted when the user closes the browser.200201202Session Interface203-----------------204205.. versionadded:: 0.8206207The session interface provides a simple way to replace the session208implementation that Flask is using.209210.. currentmodule:: flask.sessions211212.. autoclass:: SessionInterface213 :members:214215.. autoclass:: SecureCookieSessionInterface216 :members:217

Merge branch 'json-sessions'Armin Ronacherbefore adoptione1a5761

lines 218–220why, one step back
218.. autoclass:: SecureCookieSession
219 :members:220

tweaks to styleOri Livnehbefore adoption1a9e082

lines 221–226why, one step back
221.. autoclass:: NullSession
222 :members:223224.. autoclass:: SessionMixin225 :members:226

Added uuid support for new session serialization and documented itArmin Ronacherbefore adoption18673ba

lines 227–238why, one step back
227.. autodata:: session_json_serializer
228229 This object provides dumping and loading methods similar to simplejson230 but it also tags certain builtin Python objects that commonly appear in231 sessions. Currently the following extended values are supported in232 the JSON it dumps:233234 - :class:`~markupsafe.Markup` objects235 - :class:`~uuid.UUID` objects236 - :class:`~datetime.datetime` objects237 - :class:`tuple`\s238

tweaks to styleOri Livnehbefore adoption1a9e082

lines 239–272why, one step back
239.. admonition:: Notice
240241 The ``PERMANENT_SESSION_LIFETIME`` config key can also be an integer242 starting with Flask 0.8. Either catch this down yourself or use243 the :attr:`~flask.Flask.permanent_session_lifetime` attribute on the244 app which converts the result to an integer automatically.245246247Test Client248-----------249250.. currentmodule:: flask.testing251252.. autoclass:: FlaskClient253 :members:254255256Application Globals257-------------------258259.. currentmodule:: flask260261To share data that is valid for one request only from one function to262another, a global variable is not good enough because it would break in263threaded environments. Flask provides you with a special object that264ensures it is only valid for the active request and that will return265different values for each request. In a nutshell: it does the right266thing, like it does for :class:`request` and :class:`session`.267268.. data:: g269270 Just store on this whatever you want. For example a database271 connection or the user that is currently logged in.272

flask.g is now on the app context and not the request contextArmin Ronacherbefore adoption1949c4a

lines 273–274why, one step back
273 Starting with Flask 0.10 this is stored on the application context and
274 no longer on the request context which means it becomes available if

Documented changes on the g object some moreArmin Ronacherbefore adoption9307348

lines 275–278why, one step back
275 only the application context is bound and not yet a request. This
276 is especially useful when combined with the :ref:`faking-resources`277 pattern for testing.278

Changed interface for `flask.g`Armin Ronacherbefore adoptionc889fbc

lines 279–281why, one step back
279 Additionally as of 0.10 you can use the :meth:`get` method to
280 get an attribute or `None` (or the second argument) if it's not set.281 These two usages are now equivalent::

Documented changes on the g object some moreArmin Ronacherbefore adoption9307348

lines 282–283why, one step back
282
283 user = getattr(flask.g, 'user', None)

Changed interface for `flask.g`Armin Ronacherbefore adoptionc889fbc

line 284why, one step back
284 user = flask.g.get('user', None)

flask.g is now on the app context and not the request contextArmin Ronacherbefore adoption1949c4a

line 285why, one step back
285

tweaks to styleOri Livnehbefore adoption1a9e082

lines 286–295why, one step back
286 This is a proxy. See :ref:`notes-on-proxies` for more information.
287288289Useful Functions and Classes290----------------------------291292.. data:: current_app293294 Points to the application handling the request. This is useful for295 extensions that want to support multiple applications running side

Updated docs for the app context.Armin Ronacherbefore adoption0207e90

lines 296–298why, one step back
296 by side. This is powered by the application context and not by the
297 request context, so you can change the value of this proxy by298 using the :meth:`~flask.Flask.app_context` method.

tweaks to styleOri Livnehbefore adoption1a9e082

lines 299–303why, one step back
299
300 This is a proxy. See :ref:`notes-on-proxies` for more information.301302.. autofunction:: has_request_context303

Added flask.copy_current_request_context which simplies working with greenletsArmin Ronacherbefore adoption0973536

lines 304–305why, one step back
304.. autofunction:: copy_current_request_context
305

Updated docs for the app context.Armin Ronacherbefore adoption0207e90

lines 306–307why, one step back
306.. autofunction:: has_app_context
307

tweaks to styleOri Livnehbefore adoption1a9e082

lines 308–321why, one step back
308.. autofunction:: url_for
309310.. function:: abort(code)311312 Raises an :exc:`~werkzeug.exceptions.HTTPException` for the given313 status code. For example to abort request handling with a page not314 found exception, you would call ``abort(404)``.315316 :param code: the HTTP error code.317318.. autofunction:: redirect319320.. autofunction:: make_response321

Added after_this_request decorator.Armin Ronacherbefore adoption086348e

lines 322–323why, one step back
322.. autofunction:: after_this_request
323

tweaks to styleOri Livnehbefore adoption1a9e082

lines 324–341why, one step back
324.. autofunction:: send_file
325326.. autofunction:: send_from_directory327328.. autofunction:: safe_join329330.. autofunction:: escape331332.. autoclass:: Markup333 :members: escape, unescape, striptags334335Message Flashing336----------------337338.. autofunction:: flash339340.. autofunction:: get_flashed_messages341

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 342–343why, one step back
342JSON Support
343------------

tweaks to styleOri Livnehbefore adoption1a9e082

line 344why, one step back
344

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

line 345why, one step back
345.. module:: flask.json

tweaks to styleOri Livnehbefore adoption1a9e082

line 346why, one step back
346

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 347–351why, one step back
347Flask uses ``simplejson`` for the JSON implementation. Since simplejson
348is provided both by the standard library as well as extension Flask will349try simplejson first and then fall back to the stdlib json module. On top350of that it will delegate access to the current application's JSOn encoders351and decoders for easier customization.

tweaks to styleOri Livnehbefore adoption1a9e082

line 352why, one step back
352

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

line 353why, one step back
353So for starters instead of doing::

tweaks to styleOri Livnehbefore adoption1a9e082

line 354why, one step back
354

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 355–358why, one step back
355 try:
356 import simplejson as json357 except ImportError:358 import json

tweaks to styleOri Livnehbefore adoption1a9e082

line 359why, one step back
359

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

line 360why, one step back
360You can instead just do this::

tweaks to styleOri Livnehbefore adoption1a9e082

line 361why, one step back
361

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

line 362why, one step back
362 from flask import json

tweaks to styleOri Livnehbefore adoption1a9e082

line 363why, one step back
363

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 364–366why, one step back
364For usage examples, read the :mod:`json` documentation in the standard
365lirbary. The following extensions are by default applied to the stdlib's366JSON module:

tweaks to styleOri Livnehbefore adoption1a9e082

line 367why, one step back
367

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 368–371why, one step back
3681. ``datetime`` objects are serialized as :rfc:`822` strings.
3692. Any object with an ``__html__`` method (like :class:`~flask.Markup`)370 will ahve that method called and then the return value is serialized371 as string.

tweaks to styleOri Livnehbefore adoption1a9e082

line 372why, one step back
372

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 373–375why, one step back
373The :func:`~htmlsafe_dumps` function of this json module is also available
374as filter called ``|tojson`` in Jinja2. Note that inside `script`375tags no escaping must take place, so make sure to disable escaping

Imply the |safe on tojson in templates and change escaping logicArmin Ronacherbefore adoptionef72b78

lines 376–377why, one step back
376with ``|safe`` if you intend to use it inside `script` tags unless
377you are using Flask 0.10 which implies that:

tweaks to styleOri Livnehbefore adoption1a9e082

line 378why, one step back
378

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

line 379why, one step back
379.. sourcecode:: html+jinja

tweaks to styleOri Livnehbefore adoption1a9e082

line 380why, one step back
380

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 381–400why, one step back
381 <script type=text/javascript>
382 doSomethingWith({{ user.username|tojson|safe }});383 </script>384385.. autofunction:: jsonify386387.. autofunction:: dumps388389.. autofunction:: dump390391.. autofunction:: loads392393.. autofunction:: load394395.. autoclass:: JSONEncoder396 :members:397398.. autoclass:: JSONDecoder399 :members:400

tweaks to styleOri Livnehbefore adoption1a9e082

lines 401–402why, one step back
401Template Rendering
402------------------

Added wrapper module around simplejson/json for much simplified customization.Armin Ronacherbefore adoptionb146d82

lines 403–404why, one step back
403
404.. currentmodule:: flask

tweaks to styleOri Livnehbefore adoption1a9e082

lines 405–434why, one step back
405
406.. autofunction:: render_template407408.. autofunction:: render_template_string409410.. autofunction:: get_template_attribute411412Configuration413-------------414415.. autoclass:: Config416 :members:417418Extensions419----------420421.. data:: flask.ext422423 This module acts as redirect import module to Flask extensions. It was424 added in 0.8 as the canonical way to import Flask extensions and makes425 it possible for us to have more flexibility in how we distribute426 extensions.427428 If you want to use an extension named “Flask-Foo” you would import it429 from :data:`~flask.ext` as follows::430431 from flask.ext import foo432433 .. versionadded:: 0.8434

Added flask.stream_with_contextArmin Ronacherbefore adoptiond521899

lines 435–439why, one step back
435Stream Helpers
436--------------437438.. autofunction:: stream_with_context439

tweaks to styleOri Livnehbefore adoption1a9e082

lines 440–481why, one step back
440Useful Internals
441----------------442443.. autoclass:: flask.ctx.RequestContext444 :members:445446.. data:: _request_ctx_stack447448 The internal :class:`~werkzeug.local.LocalStack` that is used to implement449 all the context local objects used in Flask. This is a documented450 instance and can be used by extensions and application code but the451 use is discouraged in general.452453 The following attributes are always present on each layer of the454 stack:455456 `app`457 the active Flask application.458459 `url_adapter`460 the URL adapter that was used to match the request.461462 `request`463 the current request object.464465 `session`466 the active session object.467468 `g`469 an object with all the attributes of the :data:`flask.g` object.470471 `flashes`472 an internal cache for the flashed messages.473474 Example usage::475476 from flask import _request_ctx_stack477478 def get_session():479 ctx = _request_ctx_stack.top480 if ctx is not None:481 return ctx.session

Updated docs for the app context.Armin Ronacherbefore adoption0207e90

lines 482–491why, one step back
482
483.. autoclass:: flask.ctx.AppContext484 :members:485486.. data:: _app_ctx_stack487488 Works similar to the request context but only binds the application.489 This is mainly there for extensions to store data.490491 .. versionadded:: 0.9

tweaks to styleOri Livnehbefore adoption1a9e082

lines 492–535why, one step back
492
493.. autoclass:: flask.blueprints.BlueprintSetupState494 :members:495496Signals497-------498499.. when modifying this list, also update the one in signals.rst500501.. versionadded:: 0.6502503.. data:: signals_available504505 `True` if the signalling system is available. This is the case506 when `blinker`_ is installed.507508.. data:: template_rendered509510 This signal is sent when a template was successfully rendered. The511 signal is invoked with the instance of the template as `template`512 and the context as dictionary (named `context`).513514.. data:: request_started515516 This signal is sent before any request processing started but when the517 request context was set up. Because the request context is already518 bound, the subscriber can access the request with the standard global519 proxies such as :class:`~flask.request`.520521.. data:: request_finished522523 This signal is sent right before the response is sent to the client.524 It is passed the response to be sent named `response`.525526.. data:: got_request_exception527528 This signal is sent when an exception happens during request processing.529 It is sent *before* the standard exception handling kicks in and even530 in debug mode, where no exception handling happens. The exception531 itself is passed to the subscriber as `exception`.532533.. data:: request_tearing_down534535 This signal is sent when the application is tearing down the request.

Added documentation for appcontext and teardown handlersArmin Ronacherbefore adoption9bed20c

lines 536–546why, one step back
536 This is always called, even if an error happened. An `exc` keyword
537 argument is passed with the exception that caused the teardown.538539 .. versionchanged:: 0.9540 The `exc` parameter was added.541542.. data:: appcontext_tearing_down543544 This signal is sent when the application is tearing down the545 application context. This is always called, even if an error happened.546 An `exc` keyword argument is passed with the exception that caused the

Added appcontext_pushed and appcontext_popped signalsArmin Ronacherbefore adoption0676bb8

lines 547–562why, one step back
547 teardown. The sender is the application.
548549.. data:: appcontext_pushed550551 This signal is sent when an application context is pushed. The sender552 is the application.553554 .. versionadded:: 0.10555556.. data:: appcontext_popped557558 This signal is sent when an application context is popped. The sender559 is the application. This usually falls in line with the560 :data:`appcontext_tearing_down` signal.561562 .. versionadded:: 0.10

tweaks to styleOri Livnehbefore adoption1a9e082

line 563why, one step back
563

Documented new signal message_flashedArmin Ronacherbefore adoption0faed95

lines 564–571why, one step back
564.. data:: message_flashed
565566 This signal is sent when the application is flashing a message. The567 messages is sent as `message` keyword argument and the category as568 `category`.569570 .. versionadded:: 0.10571

tweaks to styleOri Livnehbefore adoption1a9e082

lines 572–589why, one step back
572.. currentmodule:: None
573574.. class:: flask.signals.Namespace575576 An alias for :class:`blinker.base.Namespace` if blinker is available,577 otherwise a dummy class that creates fake signals. This class is578 available for Flask extensions that want to provide the same fallback579 system as Flask itself.580581 .. method:: signal(name, doc=None)582583 Creates a new signal for this namespace if blinker is available,584 otherwise returns a fake signal that has a send method that will585 do nothing but will fail with a :exc:`RuntimeError` for all other586 operations, including connecting.587588.. _blinker: http://pypi.python.org/pypi/blinker589

Merge pull request #392 from FND/docsRon DuPlainbefore adoption7ba5196

line 590why, one step back
590Class-Based Views

tweaks to styleOri Livnehbefore adoption1a9e082

lines 591–624why, one step back
591-----------------
592593.. versionadded:: 0.7594595.. currentmodule:: None596597.. autoclass:: flask.views.View598 :members:599600.. autoclass:: flask.views.MethodView601 :members:602603.. _url-route-registrations:604605URL Route Registrations606-----------------------607608Generally there are three ways to define rules for the routing system:6096101. You can use the :meth:`flask.Flask.route` decorator.6112. You can use the :meth:`flask.Flask.add_url_rule` function.6123. You can directly access the underlying Werkzeug routing system613 which is exposed as :attr:`flask.Flask.url_map`.614615Variable parts in the route can be specified with angular brackets616(``/user/<username>``). By default a variable part in the URL accepts any617string without a slash however a different converter can be specified as618well by using ``<converter:name>``.619620Variable parts are passed to the view function as keyword arguments.621622The following converters are available:623624=========== ===============================================

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption3249eeb

line 625why, one step back
625`string` accepts any text without a slash (the default)

tweaks to styleOri Livnehbefore adoption1a9e082

lines 626–675why, one step back
626`int` accepts integers
627`float` like `int` but for floating point values628`path` like the default but also accepts slashes629=========== ===============================================630631Here are some examples::632633 @app.route('/')634 def index():635 pass636637 @app.route('/<username>')638 def show_user(username):639 pass640641 @app.route('/post/<int:post_id>')642 def show_post(post_id):643 pass644645An important detail to keep in mind is how Flask deals with trailing646slashes. The idea is to keep each URL unique so the following rules647apply:6486491. If a rule ends with a slash and is requested without a slash by the650 user, the user is automatically redirected to the same page with a651 trailing slash attached.6522. If a rule does not end with a trailing slash and the user requests the653 page with a trailing slash, a 404 not found is raised.654655This is consistent with how web servers deal with static files. This656also makes it possible to use relative link targets safely.657658You can also define multiple rules for the same function. They have to be659unique however. Defaults can also be specified. Here for example is a660definition for a URL that accepts an optional page::661662 @app.route('/users/', defaults={'page': 1})663 @app.route('/users/page/<int:page>')664 def show_users(page):665 pass666667This specifies that ``/users/`` will be the URL for page one and668``/users/page/N`` will be the URL for page `N`.669670Here are the parameters that :meth:`~flask.Flask.route` and671:meth:`~flask.Flask.add_url_rule` accept. The only difference is that672with the route parameter the view function is defined with the decorator673instead of the `view_func` parameter.674675=============== ==========================================================

Merge pull request #493 from kuyanatan/patch-1Ron DuPlainbefore adoptionfd62cd8

line 676why, one step back
676`rule` the URL rule as string

tweaks to styleOri Livnehbefore adoption1a9e082

lines 677–725why, one step back
677`endpoint` the endpoint for the registered URL rule. Flask itself
678 assumes that the name of the view function is the name679 of the endpoint if not explicitly stated.680`view_func` the function to call when serving a request to the681 provided endpoint. If this is not provided one can682 specify the function later by storing it in the683 :attr:`~flask.Flask.view_functions` dictionary with the684 endpoint as key.685`defaults` A dictionary with defaults for this rule. See the686 example above for how defaults work.687`subdomain` specifies the rule for the subdomain in case subdomain688 matching is in use. If not specified the default689 subdomain is assumed.690`**options` the options to be forwarded to the underlying691 :class:`~werkzeug.routing.Rule` object. A change to692 Werkzeug is handling of method options. methods is a list693 of methods this rule should be limited to (`GET`, `POST`694 etc.). By default a rule just listens for `GET` (and695 implicitly `HEAD`). Starting with Flask 0.6, `OPTIONS` is696 implicitly added and handled by the standard request697 handling. They have to be specified as keyword arguments.698=============== ==========================================================699700.. _view-func-options:701702View Function Options703---------------------704705For internal usage the view functions can have some attributes attached to706customize behavior the view function would normally not have control over.707The following attributes can be provided optionally to either override708some defaults to :meth:`~flask.Flask.add_url_rule` or general behavior:709710- `__name__`: The name of a function is by default used as endpoint. If711 endpoint is provided explicitly this value is used. Additionally this712 will be prefixed with the name of the blueprint by default which713 cannot be customized from the function itself.714715- `methods`: If methods are not provided when the URL rule is added,716 Flask will look on the view function object itself is an `methods`717 attribute exists. If it does, it will pull the information for the718 methods from there.719720- `provide_automatic_options`: if this attribute is set Flask will721 either force enable or disable the automatic implementation of the722 HTTP `OPTIONS` response. This can be useful when working with723 decorators that want to customize the `OPTIONS` response on a per-view724 basis.725

Added required_methodsArmin Ronacherbefore adoptiondbfd406

lines 726–729why, one step back
726- `required_methods`: if this attribute is set, Flask will always add
727 these methods when registering a URL rule even if the methods were728 explicitly overriden in the ``route()`` call.729

tweaks to styleOri Livnehbefore adoption1a9e082

lines 730–743why, one step back
730Full example::
731732 def index():733 if request.method == 'OPTIONS':734 # custom options handling here735 ...736 return 'Hello World!'737 index.provide_automatic_options = False738 index.methods = ['GET', 'OPTIONS']739740 app.add_url_rule('/', index)741742.. versionadded:: 0.8743 The `provide_automatic_options` functionality was added.