Skip to content
Myr

Merge pull request #2258 from davidism/preprocess_request-docs

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

Clean up preprocess_request docs

authored by David Lord · committed by GitHub · parents 970a800, 501f043 · Browse files · 1 file+39 added−31 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+39 added−31 removed

  • other:+39 added−31 removed

1 file+39 added−31 removed

modified:flask/app.py+39 added-31 removed
413 unmodified lines
414 #:415 #: .. versionadded:: 0.9416 self.url_build_error_handlers = []417418 #: A dictionary with lists of functions that should be called at the419 #: beginning of the request. The key of the dictionary is the name of420 #: the blueprint this function is active for, ``None`` for all requests.421 #: This can for example be used to open database connections or422 #: getting hold of the currently logged in user. To register a423 #: function here, use the :meth:`before_request` decorator.418 #: A dictionary with lists of functions that will be called at the419 #: beginning of each request. The key of the dictionary is the name of420 #: the blueprint this function is active for, or ``None`` for all421 #: requests. To register a function, use the :meth:`before_request`422 #: decorator.423 self.before_request_funcs = {}424426 #: A lists of functions that should be called at the beginning of the427 #: first request to this instance. To register a function here, use428 #: the :meth:`before_first_request` decorator.425 #: A list of functions that will be called at the beginning of the426 #: first request to this instance. To register a function, use the427 #: :meth:`before_first_request` decorator.428 #:429 #: .. versionadded:: 0.8430 self.before_first_request_funcs = []431
23 unmodified lines
455 #:456 #: .. versionadded:: 0.9457 self.teardown_appcontext_funcs = []458460 #: A dictionary with lists of functions that can be used as URL461 #: value processor functions. Whenever a URL is built these functions462 #: are called to modify the dictionary of values in place. The key463 #: ``None`` here is used for application wide464 #: callbacks, otherwise the key is the name of the blueprint.465 #: Each of these functions has the chance to modify the dictionary459 #: A dictionary with lists of functions that are called before the460 #: :attr:`before_request_funcs` functions. The key of the dictionary is461 #: the name of the blueprint this function is active for, or ``None``462 #: for all requests. To register a function, use463 #: :meth:`url_value_preprocessor`.464 #:465 #: .. versionadded:: 0.7466 self.url_value_preprocessors = {}467
843 unmodified lines
13111312 @setupmethod1313 def before_request(self, f):1314 """Registers a function to run before each request.1315 1316 For example, this can be used to open a database connection, or to load1317 the logged in user from the session.13181318 The function will be called without any arguments.1319 If the function returns a non-None value, it's handled as1320 if it was the return value from the view and further1321 request handling is stopped.1319 The function will be called without any arguments. If it returns a1320 non-None value, the value is handled as if it was the return value from1321 the view, and further request handling is stopped.1322 """1323 self.before_request_funcs.setdefault(None, []).append(f)1324 return f1325
110 unmodified lines
1436 return f14371438 @setupmethod1439 def url_value_preprocessor(self, f):1440 """Registers a function as URL value preprocessor for all view1441 functions of the application. It's called before the view functions1442 are called and can modify the url values provided.1440 """Register a URL value preprocessor function for all view1441 functions in the application. These functions will be called before the1442 :meth:`before_request` functions.1443 1444 The function can modify the values captured from the matched url before1445 they are passed to the view. For example, this can be used to pop a1446 common language code value and place it in ``g`` rather than pass it to1447 every view.1448 1449 The function is passed the endpoint name and values dict. The return1450 value is ignored.1451 """1452 self.url_value_preprocessors.setdefault(None, []).append(f)1453 return f1454
429 unmodified lines
1884 reraise(exc_type, exc_value, tb)1885 raise error18861887 def preprocess_request(self):1880 """Called before the actual request dispatching and will1881 call each :meth:`before_request` decorated function, passing no1882 arguments.1883 If any of these functions returns a value, it's handled as1884 if it was the return value from the view and further1885 request handling is stopped.18861887 This also triggers the :meth:`url_value_preprocessor` functions before1888 the actual :meth:`before_request` functions are called.1888 """Called before the request is dispatched. Calls1889 :attr:`url_value_preprocessors` registered with the app and the1890 current blueprint (if any). Then calls :attr:`before_request_funcs`1891 registered with the app and the blueprint.1892 1893 If any :meth:`before_request` handler returns a non-None value, the1894 value is handled as if it was the return value from the view, and1895 further request handling is stopped.1896 """18971898 bp = _request_ctx_stack.top.request.blueprint18991900 funcs = self.url_value_preprocessors.get(None, ())1901 if bp is not None and bp in self.url_value_preprocessors:
181 unmodified lines