|
|
|
@ -451,3 +451,41 @@ Class Based Views
|
|
|
|
|
|
|
|
|
|
.. autoclass:: flask.views.MethodView |
|
|
|
|
:members: |
|
|
|
|
|
|
|
|
|
.. _view-func-options: |
|
|
|
|
|
|
|
|
|
View Function Options |
|
|
|
|
--------------------- |
|
|
|
|
|
|
|
|
|
For internal usage the view functions can have some attributes attached to |
|
|
|
|
customize behavior the view function would normally not have control over. |
|
|
|
|
The following attributes can be provided optionally to either override |
|
|
|
|
some defaults to :meth:`~flask.Flask.add_url_rule` or general behavior: |
|
|
|
|
|
|
|
|
|
- `__name__`: The name of a function is by default used as endpoint. If |
|
|
|
|
endpoint is provided explicitly this value is used. Additionally this |
|
|
|
|
will be prefixed with the name of the blueprint by default which |
|
|
|
|
cannot be customized from the function itself. |
|
|
|
|
|
|
|
|
|
- `methods`: If methods are not provided when the URL rule is added, |
|
|
|
|
Flask will look on the view function object itself is an `methods` |
|
|
|
|
attribute exists. If it does, it will pull the information for the |
|
|
|
|
methods from there. |
|
|
|
|
|
|
|
|
|
- `provide_automatic_options`: if this attribute is set Flask will |
|
|
|
|
either force enable or disable the automatic implementation of the |
|
|
|
|
HTTP `OPTIONS` response. This can be useful when working with |
|
|
|
|
decorators that want to customize the `OPTIONS` response on a per-view |
|
|
|
|
basis. |
|
|
|
|
|
|
|
|
|
Full example:: |
|
|
|
|
|
|
|
|
|
def index(): |
|
|
|
|
if request.method == 'OPTIONS': |
|
|
|
|
# custom options handling here |
|
|
|
|
... |
|
|
|
|
return 'Hello World!' |
|
|
|
|
index.provide_automatic_options = False |
|
|
|
|
index.methods = ['GET', 'OPTIONS'] |
|
|
|
|
|
|
|
|
|
app.add_url_rule('/', index) |
|
|
|
|