1. Armin Ronacher
  2. flask


Armin Ronacher  committed b1f178b

Added _external support to url_for

  • Participants
  • Parent commits 3b9cd52
  • Branches default

Comments (0)

Files changed (3)


View file
 - :meth:`~flask.Flask.add_url_rule` can now also register a
   view function.
 - server listens on by default now to fix issues with chrome.
+- added external URL support.
 Version 0.1

File flask.py

View file
     :param endpoint: the endpoint of the URL (name of the function)
     :param values: the variable arguments of the URL rule
+    :param _external: if set to `True`, an absolute URL is generated.
-    return _request_ctx_stack.top.url_adapter.build(endpoint, values)
+    external = values.pop('_external', False)
+    return _request_ctx_stack.top.url_adapter.build(endpoint, values,
+                                                    force_external=external)
 def get_template_attribute(template_name, attribute):

File tests/flask_tests.py

View file
         with app.test_request_context():
             assert flask.url_for('hello', name='test x') == '/hello/test%20x'
+            assert flask.url_for('hello', name='test x', _external=True) \
+                == 'http://localhost/hello/test%20x'
     def test_custom_converters(self):
         from werkzeug.routing import BaseConverter