From e31a2a80ec4254e8ac8127558bc29cfd23d05511 Mon Sep 17 00:00:00 2001 From: John Hobbs Date: Fri, 11 Oct 2013 17:03:54 -0500 Subject: [PATCH] Update url_for documentation Previous documentation referenced a non-existent property on the Flask object called "build_error_handler". This should actually reference Flask.url_build_error_handlers. --- flask/helpers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flask/helpers.py b/flask/helpers.py index e59f7d3c..2d8f6d11 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -199,16 +199,16 @@ def url_for(endpoint, **values): For more information, head over to the :ref:`Quickstart `. To integrate applications, :class:`Flask` has a hook to intercept URL build - errors through :attr:`Flask.build_error_handler`. The `url_for` function - results in a :exc:`~werkzeug.routing.BuildError` when the current app does - not have a URL for the given endpoint and values. When it does, the - :data:`~flask.current_app` calls its :attr:`~Flask.build_error_handler` if + errors through :attr:`Flask.url_build_error_handlers`. The `url_for` + function results in a :exc:`~werkzeug.routing.BuildError` when the current + app does not have a URL for the given endpoint and values. When it does, the + :data:`~flask.current_app` calls its :attr:`~Flask.url_build_error_handlers` if it is not `None`, which can return a string to use as the result of `url_for` (instead of `url_for`'s default to raise the :exc:`~werkzeug.routing.BuildError` exception) or re-raise the exception. An example:: - def external_url_handler(error, endpoint, **values): + def external_url_handler(error, endpoint, values): "Looks up an external URL when `url_for` cannot build a URL." # This is an example of hooking the build_error_handler. # Here, lookup_url is some utility function you've built @@ -225,10 +225,10 @@ def url_for(endpoint, **values): # url_for will use this result, instead of raising BuildError. return url - app.build_error_handler = external_url_handler + app.url_build_error_handlers.append(external_url_handler) Here, `error` is the instance of :exc:`~werkzeug.routing.BuildError`, and - `endpoint` and `**values` are the arguments passed into `url_for`. Note + `endpoint` and `values` are the arguments passed into `url_for`. Note that this is for building URLs outside the current application, and not for handling 404 NotFound errors.