diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 4be9a63f..59e36bcc 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -160,6 +160,8 @@ The following converters exist: `path` like the default but also accepts slashes =========== =========================================== +.. _url-building: + URL Building ```````````` @@ -167,7 +169,8 @@ If it can match URLs, can it also generate them? Of course you can. To build a URL to a specific function you can use the :func:`~flask.url_for` function. It accepts the name of the function as first argument and a number of keyword arguments, each corresponding to the variable part of -the URL rule. Here some examples: +the URL rule. Unknown variable parts are appended to the URL as query +parameter. Here some examples: >>> from flask import Flask, url_for >>> app = Flask(__name__) @@ -184,9 +187,11 @@ the URL rule. Here some examples: ... print url_for('index') ... print url_for('login') ... print url_for('profile', username='John Doe') +... print url_for('login', next='/') ... / /login +/login?next=/ /user/John%20Doe (This also uses the :meth:`~flask.Flask.test_request_context` method diff --git a/flask.py b/flask.py index 32b690ca..c1c3fdb7 100644 --- a/flask.py +++ b/flask.py @@ -145,6 +145,10 @@ class _RequestContext(object): def url_for(endpoint, **values): """Generates a URL to the given endpoint with the method provided. + Variable arguments that are unknown to the target endpoint are appended + to the generated URL as query arguments. + + For more information, head over to the :ref:`Quickstart `. :param endpoint: the endpoint of the URL (name of the function) :param values: the variable arguments of the URL rule