diff --git a/flask/__init__.py b/flask/__init__.py index bf4774dcb4..85d95b4ea6 100644 --- a/flask/__init__.py +++ b/flask/__init__.py @@ -22,7 +22,7 @@ from .config import Config from .helpers import url_for, flash, send_file, send_from_directory, \ get_flashed_messages, get_template_attribute, make_response, safe_join, \ - stream_with_context + stream_with_context, redirect_url_for from .globals import current_app, g, request, session, _request_ctx_stack, \ _app_ctx_stack from .ctx import has_request_context, has_app_context, \ diff --git a/flask/helpers.py b/flask/helpers.py index c71da85b05..f350b54536 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -27,6 +27,7 @@ from werkzeug.datastructures import Headers from werkzeug.exceptions import NotFound +from werkzeug.utils import redirect # this was moved in 0.7 try: @@ -183,6 +184,12 @@ def index(): return current_app.make_response(args) +def redirect_url_for(endpoint, **values): + """Return a response object (a WSGI application) that, if called, + redirects the client to the given endpoit.""" + return redirect(url_for(endpoint, **values)) + + def url_for(endpoint, **values): """Generates a URL to the given endpoint with the method provided. diff --git a/flask/testsuite/helpers.py b/flask/testsuite/helpers.py index f8edd4e094..cb2afbb3fe 100644 --- a/flask/testsuite/helpers.py +++ b/flask/testsuite/helpers.py @@ -534,6 +534,17 @@ def post(self): self.assert_equal(flask.url_for('myview', _method='POST'), '/myview/create') + def test_redirect_url_for(self): + app = flask.Flask(__name__) + @app.route('/') + def index(): + return '42' + with app.test_request_context(): + redir = flask.redirect_url_for("index") + self.assert_equal("/", redir.location) + self.assert_equal(302, redir.status_code) + + class NoImportsTestCase(FlaskTestCase): """Test Flasks are created without import.