Skip to content
Myr

Added support for anchor link generation.

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 d04c9a6 · Browse files · 3 files+22 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+22 added−1 removed

  • other:+22 added−1 removed

3 files+22 added−1 removed

modified:flask/testsuite/helpers.py+9 added
286 unmodified lines
287 rv = app.test_client().get('/')288 self.assert_equal(rv.status_code, 500)289 self.assert_equal(rv.data, 'Hello Server Error')290291 def test_url_for_with_anchor(self):292 app = flask.Flask(__name__)293 @app.route('/')294 def index():295 return '42'296 with app.test_request_context():297 self.assert_equal(flask.url_for('index', _anchor='x y'),298 '/#x%20y')299300301def suite():302 suite = unittest.TestSuite()303 if flask.json_available:304 suite.addTest(unittest.makeSuite(JSONTestCase))
3 unmodified lines
modified:flask/helpers.py+10 added-1 removed
16 unmodified lines
17import mimetypes18from time import time19from zlib import adler3220from threading import RLock21from werkzeug.urls import url_quote2223# try to load the best simplejson implementation available. If JSON24# is not installed, we add a failing class.25json_available = True
158 unmodified lines
184 url_for('.index')185186 For more information, head over to the :ref:`Quickstart <url-building>`.187188 .. versionadded:: 0.9189 The `_anchor` parameter was added.190191 :param endpoint: the endpoint of the URL (name of the function)192 :param values: the variable arguments of the URL rule193 :param _external: if set to `True`, an absolute URL is generated.194 :param _anchor: if provided this is added as anchor to the URL.195 """196 ctx = _request_ctx_stack.top197 blueprint_name = request.blueprint198 if not ctx.request._is_old_module:
9 unmodified lines
208 endpoint = blueprint_name + '.' + endpoint209 elif endpoint.startswith('.'):210 endpoint = endpoint[1:]211 external = values.pop('_external', False)212 anchor = values.pop('_anchor', None)213 ctx.app.inject_url_defaults(endpoint, values)208 return ctx.url_adapter.build(endpoint, values, force_external=external)214 rv = ctx.url_adapter.build(endpoint, values, force_external=external)215 if anchor is not None:216 rv += '#' + url_quote(anchor)217 return rv218219220def get_template_attribute(template_name, attribute):221 """Loads a macro (or variable) a template exports. This can be used to
437 unmodified lines
modified:CHANGES+3 added
6 unmodified lines
7-----------89Relase date to be decided, codename to be chosen.1011- The :func:`flask.url_for` function now can generate anchors to the12 generated links.1314Version 0.8.115-------------1617Bugfix release, release date to be decided
293 unmodified lines