clean up preprocess_request docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
[ci skip]
authored by David Lord · committed by David Lord · parent bc7dae3 · Browse files · 1 file·+38 added−32 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+38 added−32 removed
- other:+38 added−32 removed
Provenance
- Commit
501f043- Tree
980fe26- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
bc7dae3
1 file changed+38 added−32 removed
modified:flask/app.py+38 added-32 removed
413 unmodified lines414 #:415 #: .. versionadded:: 0.9416 self.url_build_error_handlers = []417 418- #: 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 = {}424 426- #: 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 lines455 #:456 #: .. versionadded:: 0.9457 self.teardown_appcontext_funcs = []458 460- #: 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 lines1311 1312 @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.1318 1318- 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 lines1436 return f1437 1438 @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 lines1884 reraise(exc_type, exc_value, tb)1885 raise error1886 1887 def preprocess_request(self):1880- """Called before the request dispatching.1881-1882- Triggers two set of hook functions that should be invoked prior to request dispatching:1883- :attr:`url_value_preprocessors` and :attr:`before_request_funcs`1884- (the latter are functions decorated with :meth:`before_request` decorator).1885- In both cases, the method triggers only the functions that are either global1886- or registered to the current blueprint.1887-1888- If any function in :attr:`before_request_funcs` returns a value, it's handled as if it was1889- the return value from the view function, and further request handling is stopped.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 """1897 1898 bp = _request_ctx_stack.top.request.blueprint1899 183 unmodified lines