Skip to content
Myr

Documented view function options

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 3b31df8 · Browse files · 2 files+42 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

2 files+42 added−0 removed

  • other:+42 added−0 removed

2 files+42 added−0 removed

modified:docs/api.rst+38 added
449 unmodified lines
450 :members:451452.. autoclass:: flask.views.MethodView453 :members:454455.. _view-func-options:456457View Function Options458---------------------459460For internal usage the view functions can have some attributes attached to461customize behavior the view function would normally not have control over.462The following attributes can be provided optionally to either override463some defaults to :meth:`~flask.Flask.add_url_rule` or general behavior:464465- `__name__`: The name of a function is by default used as endpoint. If466 endpoint is provided explicitly this value is used. Additionally this467 will be prefixed with the name of the blueprint by default which468 cannot be customized from the function itself.469470- `methods`: If methods are not provided when the URL rule is added,471 Flask will look on the view function object itself is an `methods`472 attribute exists. If it does, it will pull the information for the473 methods from there.474475- `provide_automatic_options`: if this attribute is set Flask will476 either force enable or disable the automatic implementation of the477 HTTP `OPTIONS` response. This can be useful when working with478 decorators that want to customize the `OPTIONS` response on a per-view479 basis.480481Full example::482483 def index():484 if request.method == 'OPTIONS':485 # custom options handling here486 ...487 return 'Hello World!'488 index.provide_automatic_options = False489 index.methods = ['GET', 'OPTIONS']490491 app.add_url_rule('/', index)
modified:flask/app.py+4 added
676 unmodified lines
677 to a view function like so::678679 app.view_functions['index'] = index680681 If a view function is provided some defaults can be specified directly682 on the view function. For more information refer to683 :ref:`view-func-options`.684685 .. versionchanged:: 0.2686 `view_func` parameter added.687688 .. versionchanged:: 0.6
637 unmodified lines