Skip to content
Myr

Added required_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 2053d04 · Browse files · 3 files+14 added−1 removed
This commit

State

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

Diff stats

3 files+14 added−1 removed

  • other:+14 added−1 removed

3 files+14 added−1 removed

modified:docs/api.rst+4 added
634 unmodified lines
635 HTTP `OPTIONS` response. This can be useful when working with636 decorators that want to customize the `OPTIONS` response on a per-view637 basis.638639- `required_methods`: if this attribute is set, Flask will always add640 these methods when registering a URL rule even if the methods were641 explicitly overriden in the ``route()`` call.642643Full example::644645 def index():646 if request.method == 'OPTIONS':
10 unmodified lines
modified:flask/app.py+8 added-1 removed
913 unmodified lines
914 # methods we can use that instead. If neither exists, we go with915 # a tuple of only `GET` as default.916 if methods is None:917 methods = getattr(view_func, 'methods', None) or ('GET',)918 methods = set(methods)919920 # Methods that should always be added921 required_methods = set(getattr(view_func, 'required_methods', ()))922923 # starting with Flask 0.8 the view_func object can disable and924 # force-enable the automatic options handling.925 provide_automatic_options = getattr(view_func,926 'provide_automatic_options', None)927928 if provide_automatic_options is None:929 if 'OPTIONS' not in methods:926 methods = tuple(methods) + ('OPTIONS',)930 provide_automatic_options = True931 required_methods.add('OPTIONS')932 else:933 provide_automatic_options = False934935 # Add the required methods now.936 methods |= required_methods937938 # due to a werkzeug bug we need to make sure that the defaults are939 # None if they are an empty dictionary. This should not be necessary940 # with Werkzeug 0.7941 options['defaults'] = options.get('defaults') or None
760 unmodified lines
modified:CHANGES+2 added
66 unmodified lines
67- Changed the behavior of tuple return values from functions. They are no68 longer arguments to the response object, they now have a defined meaning.69- Added :attr:`flask.Flask.request_globals_class` to allow a specific class to70 be used on creation of the :data:`~flask.g` instance of each request.71- Added `required_methods` attribute to view functions to force-add methods72 on registration.7374Version 0.8.175-------------76
294 unmodified lines