forked from orbit-oss/flask
Added _external support to url_for
This commit is contained in:
parent
a7266ffb90
commit
75461c1467
3 changed files with 7 additions and 1 deletions
1
CHANGES
1
CHANGES
|
|
@ -14,6 +14,7 @@ Version 0.2
|
||||||
- :meth:`~flask.Flask.add_url_rule` can now also register a
|
- :meth:`~flask.Flask.add_url_rule` can now also register a
|
||||||
view function.
|
view function.
|
||||||
- server listens on 127.0.0.1 by default now to fix issues with chrome.
|
- server listens on 127.0.0.1 by default now to fix issues with chrome.
|
||||||
|
- added external URL support.
|
||||||
|
|
||||||
Version 0.1
|
Version 0.1
|
||||||
-----------
|
-----------
|
||||||
|
|
|
||||||
5
flask.py
5
flask.py
|
|
@ -152,8 +152,11 @@ def url_for(endpoint, **values):
|
||||||
|
|
||||||
:param endpoint: the endpoint of the URL (name of the function)
|
:param endpoint: the endpoint of the URL (name of the function)
|
||||||
:param values: the variable arguments of the URL rule
|
: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):
|
def get_template_attribute(template_name, attribute):
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,8 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
with app.test_request_context():
|
with app.test_request_context():
|
||||||
assert flask.url_for('hello', name='test x') == '/hello/test%20x'
|
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):
|
def test_custom_converters(self):
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue